fix: allow large OpenAI request bodies

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Zyy
2026-07-07 14:00:04 +08:00
co-authored by Codex
parent 321a286ce5
commit a6c75098be
2 changed files with 26 additions and 0 deletions
+2
View File
@@ -1,6 +1,7 @@
//! OpenAI 兼容 API 路由。
use axum::{
extract::DefaultBodyLimit,
routing::{get, post},
Router,
};
@@ -22,4 +23,5 @@ pub fn router() -> Router<AppState> {
.route("/v1/models/catalog", get(model_catalog))
.route("/v1/models/{model_id}", get(model_detail))
.route("/v1/models/{model_id}/info", get(model_info))
.layer(DefaultBodyLimit::disable())
}
@@ -59,6 +59,30 @@ async fn responses_route_should_reject_unknown_models_with_openai_error() {
);
}
#[tokio::test]
async fn responses_route_should_accept_body_larger_than_axum_default_limit() {
let (app, api_key, _dir) = test_app_with_client_api_key().await;
let large_input = "x".repeat(3 * 1024 * 1024);
let body = serde_json::json!({
"model": "unknown-model",
"input": large_input,
})
.to_string();
let response = app
.oneshot(
Request::builder()
.method("POST")
.uri("/v1/responses")
.header("authorization", format!("Bearer {api_key}"))
.header("content-type", "application/json")
.body(Body::from(body))
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::NOT_FOUND);
}
#[tokio::test]
async fn responses_route_should_terminate_generated_stream_errors_with_done_marker() {
let (app, api_key, _dir) = test_app_with_client_api_key().await;