mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-26 15:26:26 +00:00
fix(openai): pair originator with final User-Agent for codex upstream
上游 /backend-api/codex 的 404 gating 是配套校验:originator 必须与 User-Agent 首段(首个 '/' 前的 client 名)配套且为官方 codex 身份, 错配(如 originator=codex_cli_rs + UA=codex-tui/...)一律 404;version 头若携带须 >= 0.144.0。 修复: - pkg/openai 新增 PairCodexClientIdentity:由最终出站 UA 推导配套 originator(含 CODEX_INTERNAL_ORIGINATOR_OVERRIDE 尾部括号组身份恢复、 精确集合大小写归一、长度/字符集校验) - service 新增 enforceCodexIdentityHeaders 终态收口:originator 按最终 UA 重配,推导不出官方身份整体回退默认 Codex CLI 身份;version 低于 0.144.0 提升为内置版本;originator 缺失时 no-op(保护 messages bridge) - 接入非透传/透传/WS 三条转发路径(透传与 WS 删除会把 codex-tui 等官方 UA 强改为 codex_cli_rs 造成错配的旧兜底)、用量探针(指纹缓存 UA 与硬 编码 originator 错配)、账号 responses/图像测试(opencode 错配) - messages 兼容桥构建前显式打 bridge 标记,防止映射到非 gpt-5/codex 模型时收口误改其刻意最小化的请求形态 Fixes #3901
This commit is contained in:
1 parent
5260a42a0b
commit
8a51119e39
13 files changed
+406
-18
No files matched your search
@@ -10,7 +10,6 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
@@ -127,8 +126,11 @@ func (s *OpenAIGatewayService) buildOpenAIWSHeaders(
|
||||
if s != nil && s.cfg != nil && s.cfg.Gateway.ForceCodexCLI {
|
||||
headers.Set("user-agent", codexCLIUserAgent)
|
||||
}
|
||||
if account != nil && account.Type == AccountTypeOAuth && !openai.IsCodexCLIRequest(headers.Get("user-agent")) {
|
||||
headers.Set("user-agent", codexCLIUserAgent)
|
||||
// 终态收口:originator 必须与最终 user-agent 首段配套且为官方身份,非官方 UA 整体回退为
|
||||
// 默认 Codex CLI 身份(承接原「非 Codex UA 兜底」,并修复其把 codex-tui 等官方 UA 改写为
|
||||
// codex_cli_rs 造成的 originator 错配 404),详见 issue #3901。
|
||||
if account != nil && account.Type == AccountTypeOAuth {
|
||||
enforceCodexIdentityHeaders(headers)
|
||||
}
|
||||
|
||||
// 账号级请求头覆写(仅 openai api_key 账号启用时生效;OAuth 路径 no-op)。
|
||||
|
||||
Reference in new issue
Block a user