Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
7eecc49c
Unverified
Commit
7eecc49c
authored
Apr 07, 2026
by
Alex
Browse files
fix(openai): do not normalize API token based accounts
parent
9ab2fd7f
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/openai_codex_transform.go
View file @
7eecc49c
...
@@ -275,6 +275,13 @@ func normalizeCodexModel(model string) string {
...
@@ -275,6 +275,13 @@ func normalizeCodexModel(model string) string {
return
"gpt-5.1"
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
{
func
SupportsVerbosity
(
model
string
)
bool
{
if
!
strings
.
HasPrefix
(
model
,
"gpt-"
)
{
if
!
strings
.
HasPrefix
(
model
,
"gpt-"
)
{
return
true
return
true
...
...
backend/internal/service/openai_gateway_service.go
View file @
7eecc49c
...
@@ -1937,9 +1937,11 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
...
@@ -1937,9 +1937,11 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
}
}
upstreamModel
:=
billingModel
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
{
if
model
,
ok
:=
reqBody
[
"model"
]
.
(
string
);
ok
{
upstreamModel
=
normalize
CodexModel
(
model
)
upstreamModel
=
normalize
OpenAIModelForUpstream
(
account
,
model
)
if
upstreamModel
!=
""
&&
upstreamModel
!=
model
{
if
upstreamModel
!=
""
&&
upstreamModel
!=
model
{
logger
.
LegacyPrintf
(
"service.openai_gateway"
,
"[OpenAI] Upstream model resolved: %s -> %s (account: %s, type: %s, isCodexCLI: %v)"
,
logger
.
LegacyPrintf
(
"service.openai_gateway"
,
"[OpenAI] Upstream model resolved: %s -> %s (account: %s, type: %s, isCodexCLI: %v)"
,
model
,
upstreamModel
,
account
.
Name
,
account
.
Type
,
isCodexCLI
)
model
,
upstreamModel
,
account
.
Name
,
account
.
Type
,
isCodexCLI
)
...
...
backend/internal/service/openai_model_mapping_test.go
View file @
7eecc49c
...
@@ -99,3 +99,39 @@ func TestNormalizeCodexModel(t *testing.T) {
...
@@ -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
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment