From 581c51f31215ea97c68beb4fcb340ecc1a83b6d6 Mon Sep 17 00:00:00 2001 From: RedwindA Date: Thu, 9 Oct 2025 02:43:19 +0800 Subject: [PATCH] feat: add GetClaudeAuthHeader function and update FetchUpstreamModels to support Anthropic channel type --- controller/channel-billing.go | 8 ++++++++ controller/channel.go | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/controller/channel-billing.go b/controller/channel-billing.go index 1082b9e73..a7dfe9508 100644 --- a/controller/channel-billing.go +++ b/controller/channel-billing.go @@ -127,6 +127,14 @@ func GetAuthHeader(token string) http.Header { return h } +// GetClaudeAuthHeader get claude auth header +func GetClaudeAuthHeader(token string) http.Header { + h := http.Header{} + h.Add("x-api-key", token) + h.Add("anthropic-version", "2023-06-01") + return h +} + func GetResponseBody(method, url string, channel *model.Channel, headers http.Header) ([]byte, error) { req, err := http.NewRequest(method, url, nil) if err != nil { diff --git a/controller/channel.go b/controller/channel.go index 4aedee3b3..24cfa02df 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -198,9 +198,10 @@ func FetchUpstreamModels(c *gin.Context) { // 获取响应体 - 根据渠道类型决定是否添加 AuthHeader var body []byte key := strings.Split(channel.Key, "\n")[0] - if channel.Type == constant.ChannelTypeGemini { - body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) // Use AuthHeader since Gemini now forces it - } else { + switch channel.Type { + case constant.ChannelTypeAnthropic: + body, err = GetResponseBody("GET", url, channel, GetClaudeAuthHeader(key)) + default: body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) } if err != nil {