代理: 鉴权支持 Anthropic x-api-key 头
Claude Code / Anthropic SDK 用 x-api-key 头而不是 Authorization: Bearer,缺失 Authorization 时回退读取 x-api-key,错误文案同步提示两种方式 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -135,8 +135,12 @@ func (g *Gateway) Auth(c *gin.Context) {
|
||||
auth := c.GetHeader("Authorization")
|
||||
key := strings.TrimPrefix(auth, "Bearer ")
|
||||
key = strings.TrimSpace(key)
|
||||
if key == "" {
|
||||
// Anthropic 客户端(Claude Code / SDK)用 x-api-key 头而不是 Authorization
|
||||
key = strings.TrimSpace(c.GetHeader("x-api-key"))
|
||||
}
|
||||
if !apikey.Valid(key) {
|
||||
apiError(c, http.StatusUnauthorized, "invalid_api_key", "Invalid API key format. Expected: Bearer sk-...")
|
||||
apiError(c, http.StatusUnauthorized, "invalid_api_key", "Invalid API key format. Expected: Authorization: Bearer sk-... or x-api-key: sk-...")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user