From 446a0e99a891916e9929697a5cf64111b3dba991 Mon Sep 17 00:00:00 2001 From: yunyaozhou Date: Wed, 1 Jul 2026 16:26:59 +0800 Subject: [PATCH] fix: raise request body limit to 1GB --- config.example.json | 2 +- gateway.mjs | 2 +- scripts/admin-lib.mjs | 18 ++++++++++++------ scripts/install-for-current-provider.ps1 | 14 ++++++++------ scripts/run-profile.mjs | 17 +++++++++++++++-- scripts/test-gateway-e2e.mjs | 2 +- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/config.example.json b/config.example.json index 5971451..885dfb6 100644 --- a/config.example.json +++ b/config.example.json @@ -8,7 +8,7 @@ "upstream_auth_file": "", "upstream_auth_json_path": "", "upstream_auth_json_key": "OPENAI_API_KEY", - "request_body_limit_bytes": 10485760, + "request_body_limit_bytes": 1073741824, "request_history_limit": 200, "endpoints": ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"], "reasoning_equals": [516], diff --git a/gateway.mjs b/gateway.mjs index b092915..8027c46 100644 --- a/gateway.mjs +++ b/gateway.mjs @@ -38,7 +38,7 @@ const DEFAULT_CONFIG = { upstream_auth_file: "", upstream_auth_json_path: "", 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, model_remap: "", endpoints: ["/responses", "/chat/completions", "/v1/responses", "/v1/chat/completions"], diff --git a/scripts/admin-lib.mjs b/scripts/admin-lib.mjs index 7cef7ef..4137a2e 100644 --- a/scripts/admin-lib.mjs +++ b/scripts/admin-lib.mjs @@ -6,7 +6,9 @@ import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; 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_LISTEN_HOST = "127.0.0.1"; export const DEFAULT_LISTEN_PORT = 4610; @@ -368,7 +370,7 @@ export async function startGateway({ return `Gateway started. PID=${child.pid}. Listen=${getGatewayBaseUrl(gatewayConfig.listen_host, gatewayConfig.listen_port)}`; } -export async function installForCurrentProvider({ +export async function installForCurrentProvider({ codexConfigPath = DEFAULT_CODEX_CONFIG_PATH, stateRoot = DEFAULT_STATE_ROOT, listenHost = DEFAULT_LISTEN_HOST, @@ -419,10 +421,14 @@ export async function installForCurrentProvider({ listen_host: listenHost, listen_port: listenPort, upstream_base_url: originalBaseUrl, - request_body_limit_bytes: - existingGatewayConfig?.request_body_limit_bytes === undefined || existingGatewayConfig?.request_body_limit_bytes === null - ? 10485760 - : Number.parseInt(`${existingGatewayConfig.request_body_limit_bytes}`, 10), + request_body_limit_bytes: + existingGatewayConfig?.request_body_limit_bytes === undefined || existingGatewayConfig?.request_body_limit_bytes === null + ? DEFAULT_REQUEST_BODY_LIMIT_BYTES + : ( + 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, reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, [516]), retryable_status_codes: normalizeIntArray(existingGatewayConfig?.retryable_status_codes, [429, 503]), diff --git a/scripts/install-for-current-provider.ps1 b/scripts/install-for-current-provider.ps1 index bdb589d..7a48352 100644 --- a/scripts/install-for-current-provider.ps1 +++ b/scripts/install-for-current-provider.ps1 @@ -54,12 +54,14 @@ foreach ($endpoint in @( } } -$gatewayConfig = [ordered]@{ - listen_host = $ListenHost - listen_port = $ListenPort - 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 } - endpoints = @($mergedEndpoints) +$gatewayConfig = [ordered]@{ + listen_host = $ListenHost + listen_port = $ListenPort + upstream_base_url = $originalBaseUrl + 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) 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 } stream_action = if ($existingGatewayConfig -and -not [string]::IsNullOrWhiteSpace([string]$existingGatewayConfig.stream_action)) { [string]$existingGatewayConfig.stream_action } else { "strict_502" } diff --git a/scripts/run-profile.mjs b/scripts/run-profile.mjs index 64f9a35..6d7b815 100644 --- a/scripts/run-profile.mjs +++ b/scripts/run-profile.mjs @@ -28,6 +28,8 @@ import { } from "./admin-lib.mjs"; 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) { const parsed = {}; @@ -91,6 +93,17 @@ function boolFromEnv(value, fallback = false) { 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) { const mode = `${value || "passthrough"}`.trim().toLowerCase(); if (["passthrough", "fixed_bearer", "manual_bearer", "auth_json"].includes(mode)) { @@ -180,8 +193,8 @@ function buildProfileConfig({ profileName, profileEnv, existingGatewayConfig, pr upstream_base_url: upstreamBaseUrl, ...profileAuthConfig, request_body_limit_bytes: profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES - ? Number.parseInt(`${profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES}`, 10) - : Number.parseInt(`${existingGatewayConfig?.request_body_limit_bytes || 10485760}`, 10), + ? normalizeRequestBodyLimitBytes(profileEnv.CODEX_RETRY_GATEWAY_REQUEST_BODY_LIMIT_BYTES) + : normalizeRequestBodyLimitBytes(existingGatewayConfig?.request_body_limit_bytes), request_history_limit: profileEnv.CODEX_RETRY_GATEWAY_REQUEST_HISTORY_LIMIT ? Number.parseInt(`${profileEnv.CODEX_RETRY_GATEWAY_REQUEST_HISTORY_LIMIT}`, 10) : Number.parseInt(`${existingGatewayConfig?.request_history_limit || 200}`, 10), diff --git a/scripts/test-gateway-e2e.mjs b/scripts/test-gateway-e2e.mjs index ac4b57f..bf70d45 100644 --- a/scripts/test-gateway-e2e.mjs +++ b/scripts/test-gateway-e2e.mjs @@ -384,7 +384,7 @@ async function run() { listen_host: "127.0.0.1", listen_port: gatewayPort, 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"], reasoning_equals: [516], retryable_status_codes: [429, 503],