fix(openai): do not normalize API token based accounts
This commit is contained in:
@@ -275,6 +275,13 @@ func normalizeCodexModel(model string) string {
|
||||
return "gpt-5.1"
|
||||
}
|
||||
|
||||
func normalizeOpenAIModelForUpstream(account *Account, model string) string {
|
||||
if account == nil || account.Type == AccountTypeOAuth {
|
||||
return normalizeCodexModel(model)
|
||||
}
|
||||
return strings.TrimSpace(model)
|
||||
}
|
||||
|
||||
func SupportsVerbosity(model string) bool {
|
||||
if !strings.HasPrefix(model, "gpt-") {
|
||||
return true
|
||||
|
||||
@@ -1937,9 +1937,11 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
|
||||
}
|
||||
upstreamModel := billingModel
|
||||
|
||||
// 针对所有 OpenAI 账号执行 Codex 模型名规范化,确保上游识别一致。
|
||||
// OpenAI OAuth 账号走 ChatGPT internal Codex endpoint,需要将模型名规范化为
|
||||
// 上游可识别的 Codex/GPT 系列。API Key 账号则应保留原始/映射后的模型名,
|
||||
// 以兼容自定义 base_url 的 OpenAI-compatible 上游。
|
||||
if model, ok := reqBody["model"].(string); ok {
|
||||
upstreamModel = normalizeCodexModel(model)
|
||||
upstreamModel = normalizeOpenAIModelForUpstream(account, model)
|
||||
if upstreamModel != "" && upstreamModel != model {
|
||||
logger.LegacyPrintf("service.openai_gateway", "[OpenAI] Upstream model resolved: %s -> %s (account: %s, type: %s, isCodexCLI: %v)",
|
||||
model, upstreamModel, account.Name, account.Type, isCodexCLI)
|
||||
|
||||
@@ -99,3 +99,39 @@ func TestNormalizeCodexModel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeOpenAIModelForUpstream(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
account *Account
|
||||
model string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "oauth keeps codex normalization behavior",
|
||||
account: &Account{Type: AccountTypeOAuth},
|
||||
model: "gemini-3-flash-preview",
|
||||
want: "gpt-5.1",
|
||||
},
|
||||
{
|
||||
name: "apikey preserves custom compatible model",
|
||||
account: &Account{Type: AccountTypeAPIKey},
|
||||
model: "gemini-3-flash-preview",
|
||||
want: "gemini-3-flash-preview",
|
||||
},
|
||||
{
|
||||
name: "apikey preserves official non codex model",
|
||||
account: &Account{Type: AccountTypeAPIKey},
|
||||
model: "gpt-4.1",
|
||||
want: "gpt-4.1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := normalizeOpenAIModelForUpstream(tt.account, tt.model); got != tt.want {
|
||||
t.Fatalf("normalizeOpenAIModelForUpstream(...) = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user