fix: raise request body limit to 1GB

This commit is contained in:
2026-07-01 16:26:59 +08:00
parent c8cc3b153b
commit 446a0e99a8
6 changed files with 38 additions and 17 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
"upstream_auth_file": "", "upstream_auth_file": "",
"upstream_auth_json_path": "", "upstream_auth_json_path": "",
"upstream_auth_json_key": "OPENAI_API_KEY", "upstream_auth_json_key": "OPENAI_API_KEY",
"request_body_limit_bytes": 10485760, "request_body_limit_bytes": 1073741824,
"request_history_limit": 200, "request_history_limit": 200,
"endpoints": ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"], "endpoints": ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"],
"reasoning_equals": [516], "reasoning_equals": [516],
+1 -1
View File
@@ -38,7 +38,7 @@ const DEFAULT_CONFIG = {
upstream_auth_file: "", upstream_auth_file: "",
upstream_auth_json_path: "", upstream_auth_json_path: "",
upstream_auth_json_key: "OPENAI_API_KEY", upstream_auth_json_key: "OPENAI_API_KEY",
request_body_limit_bytes: 10 * 1024 * 1024, request_body_limit_bytes: 1024 * 1024 * 1024,
request_history_limit: 0, request_history_limit: 0,
model_remap: "", model_remap: "",
endpoints: ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"], endpoints: ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"],
+8 -2
View File
@@ -7,6 +7,8 @@ import os from "node:os";
import path from "node:path"; import path from "node:path";
export const DEFAULT_STATE_ROOT = path.join(os.homedir(), ".codex-retry-gateway"); export const DEFAULT_STATE_ROOT = path.join(os.homedir(), ".codex-retry-gateway");
const DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024 * 1024;
const LEGACY_DEFAULT_REQUEST_BODY_LIMIT_BYTES = 10 * 1024 * 1024;
export const DEFAULT_CODEX_CONFIG_PATH = path.join(os.homedir(), ".codex", "config.toml"); export const DEFAULT_CODEX_CONFIG_PATH = path.join(os.homedir(), ".codex", "config.toml");
export const DEFAULT_LISTEN_HOST = "127.0.0.1"; export const DEFAULT_LISTEN_HOST = "127.0.0.1";
export const DEFAULT_LISTEN_PORT = 4610; export const DEFAULT_LISTEN_PORT = 4610;
@@ -421,8 +423,12 @@ export async function installForCurrentProvider({
upstream_base_url: originalBaseUrl, upstream_base_url: originalBaseUrl,
request_body_limit_bytes: request_body_limit_bytes:
existingGatewayConfig?.request_body_limit_bytes === undefined || existingGatewayConfig?.request_body_limit_bytes === null existingGatewayConfig?.request_body_limit_bytes === undefined || existingGatewayConfig?.request_body_limit_bytes === null
? 10485760 ? DEFAULT_REQUEST_BODY_LIMIT_BYTES
: Number.parseInt(`${existingGatewayConfig.request_body_limit_bytes}`, 10), : (
Number.parseInt(`${existingGatewayConfig.request_body_limit_bytes}`, 10) === LEGACY_DEFAULT_REQUEST_BODY_LIMIT_BYTES
? DEFAULT_REQUEST_BODY_LIMIT_BYTES
: Number.parseInt(`${existingGatewayConfig.request_body_limit_bytes}`, 10)
),
endpoints: mergedEndpoints, endpoints: mergedEndpoints,
reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, [516]), reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, [516]),
retryable_status_codes: normalizeIntArray(existingGatewayConfig?.retryable_status_codes, [429, 503]), retryable_status_codes: normalizeIntArray(existingGatewayConfig?.retryable_status_codes, [429, 503]),
+3 -1
View File
@@ -58,7 +58,9 @@ $gatewayConfig = [ordered]@{
listen_host = $ListenHost listen_host = $ListenHost
listen_port = $ListenPort listen_port = $ListenPort
upstream_base_url = $originalBaseUrl upstream_base_url = $originalBaseUrl
request_body_limit_bytes = if ($existingGatewayConfig -and $null -ne $existingGatewayConfig.request_body_limit_bytes) { [int]$existingGatewayConfig.request_body_limit_bytes } else { 10485760 } request_body_limit_bytes = if ($existingGatewayConfig -and $null -ne $existingGatewayConfig.request_body_limit_bytes) {
if ([int]$existingGatewayConfig.request_body_limit_bytes -eq 10485760) { 1073741824 } else { [int]$existingGatewayConfig.request_body_limit_bytes }
} else { 1073741824 }
endpoints = @($mergedEndpoints) endpoints = @($mergedEndpoints)
reasoning_equals = Normalize-IntArray -Values $(if ($existingGatewayConfig) { $existingGatewayConfig.reasoning_equals } else { $null }) -Default @(516) reasoning_equals = Normalize-IntArray -Values $(if ($existingGatewayConfig) { $existingGatewayConfig.reasoning_equals } else { $null }) -Default @(516)
non_stream_status_code = if ($existingGatewayConfig -and $null -ne $existingGatewayConfig.non_stream_status_code) { [int]$existingGatewayConfig.non_stream_status_code } else { 502 } non_stream_status_code = if ($existingGatewayConfig -and $null -ne $existingGatewayConfig.non_stream_status_code) { [int]$existingGatewayConfig.non_stream_status_code } else { 502 }
+15 -2
View File
@@ -28,6 +28,8 @@ import {
} from "./admin-lib.mjs"; } from "./admin-lib.mjs";
const DEFAULT_PROFILES_DIR = path.join(os.homedir(), ".config", "codex-retry-gateway", "profiles"); const DEFAULT_PROFILES_DIR = path.join(os.homedir(), ".config", "codex-retry-gateway", "profiles");
const DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024 * 1024;
const LEGACY_DEFAULT_REQUEST_BODY_LIMIT_BYTES = 10 * 1024 * 1024;
function parseEnvFile(content) { function parseEnvFile(content) {
const parsed = {}; const parsed = {};
@@ -91,6 +93,17 @@ function boolFromEnv(value, fallback = false) {
return ["1", "true", "yes", "on"].includes(`${value}`.trim().toLowerCase()); return ["1", "true", "yes", "on"].includes(`${value}`.trim().toLowerCase());
} }
function normalizeRequestBodyLimitBytes(value) {
const parsed = Number.parseInt(`${value ?? ""}`, 10);
if (!Number.isFinite(parsed) || parsed <= 0) {
return DEFAULT_REQUEST_BODY_LIMIT_BYTES;
}
if (parsed === LEGACY_DEFAULT_REQUEST_BODY_LIMIT_BYTES) {
return DEFAULT_REQUEST_BODY_LIMIT_BYTES;
}
return parsed;
}
function normalizeAuthMode(value) { function normalizeAuthMode(value) {
const mode = `${value || "passthrough"}`.trim().toLowerCase(); const mode = `${value || "passthrough"}`.trim().toLowerCase();
if (["passthrough", "fixed_bearer", "manual_bearer", "auth_json"].includes(mode)) { if (["passthrough", "fixed_bearer", "manual_bearer", "auth_json"].includes(mode)) {
@@ -180,8 +193,8 @@ function buildProfileConfig({ profileName, profileEnv, existingGatewayConfig, pr
upstream_base_url: upstreamBaseUrl, upstream_base_url: upstreamBaseUrl,
...profileAuthConfig, ...profileAuthConfig,
request_body_limit_bytes: profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES request_body_limit_bytes: profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES
? Number.parseInt(`${profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES}`, 10) ? normalizeRequestBodyLimitBytes(profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES)
: Number.parseInt(`${existingGatewayConfig?.request_body_limit_bytes || 10485760}`, 10), : normalizeRequestBodyLimitBytes(existingGatewayConfig?.request_body_limit_bytes),
request_history_limit: profileEnv.CODEX_RETRY_GATEWAY_REQUEST_HISTORY_LIMIT request_history_limit: profileEnv.CODEX_RETRY_GATEWAY_REQUEST_HISTORY_LIMIT
? Number.parseInt(`${profileEnv.CODEX_RETRY_GATEWAY_REQUEST_HISTORY_LIMIT}`, 10) ? Number.parseInt(`${profileEnv.CODEX_RETRY_GATEWAY_REQUEST_HISTORY_LIMIT}`, 10)
: Number.parseInt(`${existingGatewayConfig?.request_history_limit || 200}`, 10), : Number.parseInt(`${existingGatewayConfig?.request_history_limit || 200}`, 10),
+1 -1
View File
@@ -384,7 +384,7 @@ async function run() {
listen_host: "127.0.0.1", listen_host: "127.0.0.1",
listen_port: gatewayPort, listen_port: gatewayPort,
upstream_base_url: `http://127.0.0.1:${upstreamPort}`, upstream_base_url: `http://127.0.0.1:${upstreamPort}`,
request_body_limit_bytes: 10 * 1024 * 1024, request_body_limit_bytes: 1024 * 1024 * 1024,
endpoints: ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"], endpoints: ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"],
reasoning_equals: [516], reasoning_equals: [516],
retryable_status_codes: [429, 503], retryable_status_codes: [429, 503],