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
0c011b88
Commit
0c011b88
authored
Jan 16, 2026
by
cyhhao
Browse files
fix(网关): Claude Code OAuth 补齐 oauth beta
parent
0962ba43
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/gateway_service.go
View file @
0c011b88
...
...
@@ -2820,12 +2820,19 @@ func (s *GatewayService) buildUpstreamRequest(ctx context.Context, c *gin.Contex
applyClaudeOAuthHeaderDefaults
(
req
,
reqStream
)
}
// 处理anthropic-beta header(OAuth账号需要特殊处理)
if
tokenType
==
"oauth"
&&
mimicClaudeCode
{
if
requestHasTools
(
body
)
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
MessageBetaHeaderWithTools
)
// 处理 anthropic-beta header(OAuth 账号需要包含 oauth beta)
if
tokenType
==
"oauth"
{
if
mimicClaudeCode
{
// 非 Claude Code 客户端:按 Claude Code 规则生成 beta header
if
requestHasTools
(
body
)
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
MessageBetaHeaderWithTools
)
}
else
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
MessageBetaHeaderNoTools
)
}
}
else
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
MessageBetaHeaderNoTools
)
// Claude Code 客户端:尽量透传原始 header,仅补齐 oauth beta
clientBetaHeader
:=
req
.
Header
.
Get
(
"anthropic-beta"
)
req
.
Header
.
Set
(
"anthropic-beta"
,
s
.
getBetaHeader
(
modelID
,
clientBetaHeader
))
}
}
else
if
s
.
cfg
!=
nil
&&
s
.
cfg
.
Gateway
.
InjectBetaForAPIKey
&&
req
.
Header
.
Get
(
"anthropic-beta"
)
==
""
{
// API-key:仅在请求显式使用 beta 特性且客户端未提供时,按需补齐(默认关闭)
...
...
@@ -4070,8 +4077,21 @@ func (s *GatewayService) buildCountTokensRequest(ctx context.Context, c *gin.Con
}
// OAuth 账号:处理 anthropic-beta header
if
tokenType
==
"oauth"
&&
mimicClaudeCode
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
CountTokensBetaHeader
)
if
tokenType
==
"oauth"
{
if
mimicClaudeCode
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
CountTokensBetaHeader
)
}
else
{
clientBetaHeader
:=
req
.
Header
.
Get
(
"anthropic-beta"
)
if
clientBetaHeader
==
""
{
req
.
Header
.
Set
(
"anthropic-beta"
,
claude
.
CountTokensBetaHeader
)
}
else
{
beta
:=
s
.
getBetaHeader
(
modelID
,
clientBetaHeader
)
if
!
strings
.
Contains
(
beta
,
claude
.
BetaTokenCounting
)
{
beta
=
beta
+
","
+
claude
.
BetaTokenCounting
}
req
.
Header
.
Set
(
"anthropic-beta"
,
beta
)
}
}
}
else
if
s
.
cfg
!=
nil
&&
s
.
cfg
.
Gateway
.
InjectBetaForAPIKey
&&
req
.
Header
.
Get
(
"anthropic-beta"
)
==
""
{
// API-key:与 messages 同步的按需 beta 注入(默认关闭)
if
requestNeedsBetaFeatures
(
body
)
{
...
...
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