fix: 账号测试根据类型使用不同的 beta header

- OAuth 账号:使用完整的 DefaultBetaHeader 和 Claude Code 客户端 headers
- API Key 账号:使用 APIKeyBetaHeader(不含 oauth beta)
This commit is contained in:
shaw
2026-02-07 11:29:22 +08:00
parent 35a55e10aa
commit 39a5b17d31

View File

@@ -245,17 +245,19 @@ func (s *AccountTestService) testClaudeAccountConnection(c *gin.Context, account
// Set common headers // Set common headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("anthropic-version", "2023-06-01") req.Header.Set("anthropic-version", "2023-06-01")
req.Header.Set("anthropic-beta", claude.DefaultBetaHeader)
// Apply Claude Code client headers // Set authentication header and beta header based on account type
for key, value := range claude.DefaultHeaders {
req.Header.Set(key, value)
}
// Set authentication header
if useBearer { if useBearer {
// OAuth 账号使用完整的 Claude Code beta header
req.Header.Set("anthropic-beta", claude.DefaultBetaHeader)
req.Header.Set("Authorization", "Bearer "+authToken) req.Header.Set("Authorization", "Bearer "+authToken)
// Apply Claude Code client headers for OAuth
for key, value := range claude.DefaultHeaders {
req.Header.Set(key, value)
}
} else { } else {
// API Key 账号使用简化的 beta header不含 oauth
req.Header.Set("anthropic-beta", claude.APIKeyBetaHeader)
req.Header.Set("x-api-key", authToken) req.Header.Set("x-api-key", authToken)
} }