fix(proxy): align Codex OAuth client identity

ChatGPT's Codex backend routes model availability by the originator and version header pair. Requests identifying as cc-switch without a version were assigned to a cohort where gpt-5.6-luna resolved to an unavailable internal engine, resulting in a misleading 404 Model not found response.

Identify takeover requests as codex_cli_rs and send version 0.144.1, satisfying luna's minimal_client_version requirement of 0.144.0. A direct HTTP A/B test confirmed the existing headers returned 404 while the aligned identity completed successfully, so no WebSocket transport workaround is required.
This commit is contained in:
Jason
2026-07-13 11:53:09 +08:00
parent 99573d2242
commit af58740bcd
2 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ pub enum AuthStrategy {
/// ///
/// - Header: `Authorization: Bearer <access_token>` /// - Header: `Authorization: Bearer <access_token>`
/// - Header: `ChatGPT-Account-Id: <account_id>` (来自 forwarder 注入) /// - Header: `ChatGPT-Account-Id: <account_id>` (来自 forwarder 注入)
/// - Header: `originator: cc-switch` /// - Header: `originator: codex_cli_rs` + `version: <codex 版本>`(成对,后端按此做模型 cohort 路由)
/// ///
/// 使用动态获取的 OpenAI access_token(通过 Device Code 流程获取) /// 使用动态获取的 OpenAI access_token(通过 Device Code 流程获取)
CodexOAuth, CodexOAuth,
+12 -1
View File
@@ -24,6 +24,13 @@ const ANTHROPIC_REDACTED_THINKING_PLACEHOLDER: &str = "[redacted thinking]";
// Keep hints lowercase; matching lowercases only the input value. // Keep hints lowercase; matching lowercases only the input value.
const REASONING_VENDOR_HINTS: &[&str] = &["moonshot", "kimi", "deepseek", "mimo", "xiaomimimo"]; const REASONING_VENDOR_HINTS: &[&str] = &["moonshot", "kimi", "deepseek", "mimo", "xiaomimimo"];
// ChatGPT Codex 后端按 originator+version 组合做模型 cohort 路由:非官方身份会把
// gpt-5.6-luna 解析到未部署的内部引擎(HTTP 404 Model not foundopenai/codex#31967
// 本机 A/B 实测确认)。两个头必须成对发送,缺一即 404;version 需 ≥ 目标模型
// catalog 的 minimal_client_versionluna=0.144.0),新模型抬门槛时同步 bump。
const CODEX_OAUTH_ORIGINATOR: &str = "codex_cli_rs";
const CODEX_OAUTH_CLIENT_VERSION: &str = "0.144.1";
/// 获取 Claude 供应商的 API 格式 /// 获取 Claude 供应商的 API 格式
/// ///
/// 供 handler/forwarder 外部使用的公开函数。 /// 供 handler/forwarder 外部使用的公开函数。
@@ -843,7 +850,11 @@ impl ProviderAdapter for ClaudeAdapter {
(HeaderName::from_static("authorization"), hv(&bearer)?), (HeaderName::from_static("authorization"), hv(&bearer)?),
( (
HeaderName::from_static("originator"), HeaderName::from_static("originator"),
HeaderValue::from_static("cc-switch"), HeaderValue::from_static(CODEX_OAUTH_ORIGINATOR),
),
(
HeaderName::from_static("version"),
HeaderValue::from_static(CODEX_OAUTH_CLIENT_VERSION),
), ),
] ]
} }