feat(proxy): session-based prompt_cache_key routing for Codex Chat bridge

Codex always sends prompt_cache_key in its Responses requests, but the
Responses -> Chat Completions conversion dropped it, breaking session
cache affinity on upstreams that route by key (e.g. Kimi Coding).

- Re-inject prompt_cache_key after conversion in the forwarder: an
  explicit client key wins, otherwise a client-provided session ID;
  generated per-request UUIDs are never sent upstream.
- Provider-aware gating: "auto" enables only known-compatible upstreams
  (api.openai.com, api.kimi.com/coding) because strict gateways reject
  unknown fields with HTTP 400 (e.g. Fireworks); an advanced
  Auto/Enabled/Disabled override is available on the Codex form in all
  four locales.
- Kimi For Coding preset opts in explicitly.
This commit is contained in:
Jason
2026-07-11 21:42:43 +08:00
parent 0e563b50c5
commit a078b4b207
14 changed files with 295 additions and 4 deletions
+5
View File
@@ -1284,6 +1284,11 @@
"maxOutputTokensLabel": "Max output tokens",
"maxOutputTokensPlaceholder": "Leave empty to use the default 8192",
"maxOutputTokensHint": "Codex does not forward model_max_output_tokens in the request body, so the default 8192 ceiling can truncate long or thinking-heavy responses (stop_reason=max_tokens). This value overrides the request's max_tokens on the Anthropic path. Do not exceed the real output ceiling of the model/gateway or it may 400. Leave empty to use the default 8192.",
"promptCacheRoutingLabel": "Prompt cache routing",
"promptCacheRoutingAuto": "Auto (recommended)",
"promptCacheRoutingEnabled": "Enabled",
"promptCacheRoutingDisabled": "Disabled",
"promptCacheRoutingHint": "Auto sends prompt_cache_key only to known-compatible upstreams. Enable it for other compatible gateways, or disable it if a strict gateway rejects unknown fields with HTTP 400. Only a stable client-provided session ID is used.",
"upstreamModelName": "Upstream Model Name",
"upstreamModelNameHint": "For Chat format, enter the real upstream model here; routing converts Codex Responses requests to Chat Completions while keeping this model.",
"modelNamePlaceholder": "e.g., gpt-5-codex",
+5
View File
@@ -1284,6 +1284,11 @@
"maxOutputTokensLabel": "最大出力トークン",
"maxOutputTokensPlaceholder": "空欄の場合はデフォルトの 8192 を使用",
"maxOutputTokensHint": "Codex は model_max_output_tokens をリクエストボディに含めないため、デフォルト上限 8192 では長い回答や深い思考時に切り詰められることがあります(stop_reason=max_tokens)。この値は Anthropic 経路で max_tokens を上書きします。モデル/ゲートウェイの実際の出力上限を超えると 400 になる場合があります。空欄でデフォルトの 8192 を使用します。",
"promptCacheRoutingLabel": "プロンプトキャッシュルーティング",
"promptCacheRoutingAuto": "自動(推奨)",
"promptCacheRoutingEnabled": "有効",
"promptCacheRoutingDisabled": "無効",
"promptCacheRoutingHint": "自動モードでは、互換性を確認済みの上流にのみ prompt_cache_key を送信します。他の互換ゲートウェイでは有効にし、未知のフィールドを 400 で拒否する厳格なゲートウェイでは無効にしてください。クライアントが提供した安定したセッション ID のみを使用します。",
"upstreamModelName": "上流モデル名",
"upstreamModelNameHint": "Chat 形式ではここに実際の上流モデルを入力します。ルーティングで Codex の Responses リクエストを Chat Completions に変換し、このモデルを維持します。",
"modelNamePlaceholder": "例: gpt-5-codex",
+5
View File
@@ -1261,6 +1261,11 @@
"maxOutputTokensLabel": "最大輸出 tokens",
"maxOutputTokensPlaceholder": "留空則使用預設 8192",
"maxOutputTokensHint": "Codex 不會把 model_max_output_tokens 寫進請求體,預設上限 8192 容易在長回答或深度思考時被截斷(stop_reason=max_tokens)。此處設定會作為 Anthropic 的 max_tokens 覆蓋請求值。請勿超過該模型/閘道的真實輸出上限,否則可能 400。留空使用預設 8192。",
"promptCacheRoutingLabel": "提示詞快取路由",
"promptCacheRoutingAuto": "自動(建議)",
"promptCacheRoutingEnabled": "開啟",
"promptCacheRoutingDisabled": "關閉",
"promptCacheRoutingHint": "自動模式僅對已確認相容的上游傳送 prompt_cache_key;開啟可用於其他相容閘道,關閉可避免嚴格閘道因未知欄位回傳 400。只使用客戶端提供的穩定工作階段 ID。",
"defaultModelLabel": "預設模型",
"defaultModelPlaceholder": "例如: gpt-5.6",
"defaultModelHint": "Codex 預設請求的模型,隨時可改,無需等待軟體更新供應商範本。留空且設定了模型映射時,預設使用映射第一行。",
+5
View File
@@ -1284,6 +1284,11 @@
"maxOutputTokensLabel": "最大输出 tokens",
"maxOutputTokensPlaceholder": "留空则使用默认 8192",
"maxOutputTokensHint": "Codex 不会把 model_max_output_tokens 写进请求体,默认上限 8192 容易在长回答或深度思考时被截断(stop_reason=max_tokens)。此处设置会作为 Anthropic 的 max_tokens 覆盖请求值。请勿超过该模型/网关的真实输出上限,否则可能 400。留空使用默认 8192。",
"promptCacheRoutingLabel": "提示词缓存路由",
"promptCacheRoutingAuto": "自动(推荐)",
"promptCacheRoutingEnabled": "开启",
"promptCacheRoutingDisabled": "关闭",
"promptCacheRoutingHint": "自动模式仅对已确认兼容的上游发送 prompt_cache_key;开启可用于其他兼容网关,关闭可避免严格网关因未知字段返回 400。只使用客户端提供的稳定会话 ID。",
"upstreamModelName": "上游模型名称",
"upstreamModelNameHint": "Chat 格式下这里填写真实上游模型;路由会把 Codex 的 Responses 请求转换为 Chat Completions 并保持该模型。",
"modelNamePlaceholder": "例如: gpt-5-codex",