Merge pull request #1984 from RedwindA/feat/claude-fetchModels

feat: add GetClaudeAuthHeader function and update FetchUpstreamModels to support Anthropic channel type
This commit is contained in:
Seefs
2025-10-09 12:22:47 +08:00
committed by GitHub
2 changed files with 12 additions and 3 deletions

View File

@@ -127,6 +127,14 @@ func GetAuthHeader(token string) http.Header {
return h 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) { func GetResponseBody(method, url string, channel *model.Channel, headers http.Header) ([]byte, error) {
req, err := http.NewRequest(method, url, nil) req, err := http.NewRequest(method, url, nil)
if err != nil { if err != nil {

View File

@@ -198,9 +198,10 @@ func FetchUpstreamModels(c *gin.Context) {
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader // 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
var body []byte var body []byte
key := strings.Split(channel.Key, "\n")[0] key := strings.Split(channel.Key, "\n")[0]
if channel.Type == constant.ChannelTypeGemini { switch channel.Type {
body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) // Use AuthHeader since Gemini now forces it case constant.ChannelTypeAnthropic:
} else { body, err = GetResponseBody("GET", url, channel, GetClaudeAuthHeader(key))
default:
body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key))
} }
if err != nil { if err != nil {