Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions controller/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ type GoogleOpenAICompatibleResponse struct {
NextPageToken string `json:"nextPageToken"`
}

// AnthropicModel 定义Anthropic API返回的模型结构
type AnthropicModel struct {
ID string `json:"id"`
CreatedAt string `json:"created_at"`
DisplayName string `json:"display_name"`
Type string `json:"type"`
}

// AnthropicModelsResponse 定义Anthropic API响应结构
type AnthropicModelsResponse struct {
Data []AnthropicModel `json:"data"`
FirstID string `json:"first_id"`
HasMore bool `json:"has_more"`
LastID string `json:"last_id"`
}

func parseStatusFilter(statusParam string) int {
switch strings.ToLower(statusParam) {
case "enabled", "1":
Expand Down Expand Up @@ -201,9 +217,16 @@ func FetchUpstreamModels(c *gin.Context) {

// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
var body []byte
if channel.Type == constant.ChannelTypeGemini {
switch channel.Type {
case constant.ChannelTypeGemini:
body, err = GetResponseBody("GET", url, channel, nil) // I don't know why, but Gemini requires no AuthHeader
} else {
case constant.ChannelTypeAnthropic:
// Authropic模型获取Header
header := http.Header{}
header.Add("x-api-key", channel.Key)
header.Add("anthropic-version", "2023-06-01")
body, err = GetResponseBody("GET", url, channel, header)
Comment on lines +223 to +228

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the Anthropic API version and consider making it configurable.

The implementation correctly sets the required headers for Anthropic API calls. However, the hardcoded version "2023-06-01" should be verified to ensure it's current and supported.


🌐 Web query:

What is the current recommended API version for Anthropic Claude models API?

💡 Result:

As of August 2, 2025, the recommended API version for Anthropic's Claude models is 2025-05-22. This version corresponds to the latest releases of Claude Sonnet 4 and Claude Opus 4, which were introduced on May 22, 2025. (docs.anthropic.com)

To ensure compatibility and access to the latest features, it's advisable to include the anthropic-version header in your API requests, specifying this version. For example:

anthropic-version: 2025-05-22

This practice helps maintain consistent behavior and leverages the most recent advancements in the Claude models.

Citations:


Update Anthropic API version and make it configurable

The hardcoded header value "2023-06-01" is now outdated. According to Anthropic’s docs, the current recommended version is 2025-05-22. To prevent this drifting out of sync in the future, pull the version string from configuration (or define it as a shared constant) rather than embedding it in the call site.

Locations to update:

  • controller/channel.go (around line 225)

Suggested diff:

--- a/controller/channel.go
+++ b/controller/channel.go
@@ case constant.ChannelTypeAnthropic:
-       header.Add("anthropic-version", "2023-06-01")
+       // Use configured Anthropic API version (defaults to latest: 2025-05-22)
+       header.Add("anthropic-version", config.AnthropicAPIVersion)

• Define AnthropicAPIVersion in your config (e.g., via env var or a constants file) with default "2025-05-22".
• This ensures you can bump the version globally without touching each call site.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In controller/channel.go around lines 223 to 228, the Anthropic API version
header is hardcoded as "2023-06-01", which is outdated. To fix this, define a
shared constant or configuration variable named AnthropicAPIVersion with the
value "2025-05-22" (e.g., in a config or constants file). Then replace the
hardcoded version string in the header.Add call with this constant to make the
version configurable and maintainable.

default:
body, err = GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
}
if err != nil {
Expand All @@ -229,6 +252,17 @@ func FetchUpstreamModels(c *gin.Context) {
}
parseSuccess = true
}
case constant.ChannelTypeAnthropic:
var anthropicResult AnthropicModelsResponse
if err = json.Unmarshal(body, &anthropicResult); err == nil {
// 转换Anthropic格式到OpenAI格式
for _, model := range anthropicResult.Data {
result.Data = append(result.Data, OpenAIModel{
ID: model.ID,
})
}
parseSuccess = true
}
}

// 如果解析失败,尝试OpenAI格式
Expand Down