Skip to content

fix:Get Claude Models - #1491

Closed
nekohy wants to merge 1 commit into
QuantumNous:alphafrom
nekohy:fix-get-claude-models
Closed

fix:Get Claude Models#1491
nekohy wants to merge 1 commit into
QuantumNous:alphafrom
nekohy:fix-get-claude-models

Conversation

@nekohy

@nekohy nekohy commented Aug 2, 2025

Copy link
Copy Markdown
Contributor

Thx to #1448, but I want to streamline it, only fix the issue with getting Claude models

Summary by CodeRabbit

  • New Features

    • Added support for Anthropic channel type when fetching available models.
  • Bug Fixes

    • Improved handling of model responses for Anthropic channels to ensure accurate model listing.

@coderabbitai

coderabbitai Bot commented Aug 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change adds support for the Anthropic channel type in the model fetching logic. It introduces new structs to represent Anthropic's model response format, updates request header handling for Anthropic, and extends the response parsing logic to convert Anthropic models into the existing internal format.

Changes

Cohort / File(s) Change Summary
Anthropic Channel Support
controller/channel.go
Added AnthropicModel and AnthropicModelsResponse structs; updated FetchUpstreamModels to handle Anthropic channel headers and response parsing.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant AnthropicAPI

    Client->>Controller: FetchUpstreamModels(channelType=Anthropic)
    Controller->>AnthropicAPI: GET /models (with x-api-key, anthropic-version headers)
    AnthropicAPI-->>Controller: AnthropicModelsResponse
    Controller->>Controller: Unmarshal response to AnthropicModelsResponse
    Controller->>Controller: Convert to OpenAIModel format
    Controller-->>Client: Return models list
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A new friend joins the channel crew,
Anthropic hops in, models fresh and new!
With headers set and structs aligned,
The models list is well-defined.
Rabbits cheer for code so neat—
More channels now, a hopping feat! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c056a7a and 6768a52.

📒 Files selected for processing (1)
  • controller/channel.go (3 hunks)
🔇 Additional comments (3)
controller/channel.go (3)

63-69: LGTM! Well-structured Anthropic model representation.

The AnthropicModel struct properly defines the expected fields from Anthropic's API response with appropriate JSON tags.


71-77: LGTM! Proper pagination response structure.

The AnthropicModelsResponse struct correctly handles paginated responses with appropriate fields for data and pagination metadata.


255-265: LGTM! Proper response parsing and format conversion.

The Anthropic response parsing correctly:

  • Unmarshals the API response into the appropriate struct
  • Converts to the standardized OpenAI format used internally
  • Follows the established pattern for model ID extraction
  • Maintains consistency with other provider implementations

Comment thread controller/channel.go
Comment on lines +223 to +228
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)

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.

@nekohy nekohy closed this Aug 9, 2025
@nekohy
nekohy deleted the fix-get-claude-models branch August 12, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant