Skip to content

Conform Claude models listing to Anthropic API schema#3834

Merged
luispater merged 4 commits into
router-for-me:devfrom
dcrdev:main
Jun 20, 2026
Merged

Conform Claude models listing to Anthropic API schema#3834
luispater merged 4 commits into
router-for-me:devfrom
dcrdev:main

Conversation

@dcrdev

@dcrdev dcrdev commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Anthropic's List Models response (GET /v1/models) defines each model object with id, display_name, max_input_tokens, max_tokens, created_at and type. The Claude case of convertModelToMap emitted an incomplete object: it dropped max_input_tokens and max_tokens entirely and omitted display_name whenever it was unset, so the Anthropic-compatible listing did not match the schema it emulates.

Emit max_input_tokens from ContextLength and max_tokens from MaxCompletionTokens (the same registry metadata the Gemini case already surfaces as inputTokenLimit/outputTokenLimit), with fallbacks, and always emit display_name, falling back to the model ID.

Fixes: #3833

Anthropic's List Models response (GET /v1/models) defines each model object
with id, display_name, max_input_tokens, max_tokens, created_at and type.
The Claude case of convertModelToMap emitted an incomplete object: it dropped
max_input_tokens and max_tokens entirely and omitted display_name whenever it
was unset, so the Anthropic-compatible listing did not match the schema it
emulates.

Emit max_input_tokens from ContextLength and max_tokens from
MaxCompletionTokens (the same registry metadata the Gemini case already
surfaces as inputTokenLimit/outputTokenLimit), with fallbacks, and always
emit display_name, falling back to the model ID.
@github-actions github-actions Bot changed the base branch from main to dev June 13, 2026 15:08
@github-actions

Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds default token limits (max_input_tokens and max_tokens) and display name fallbacks for Claude models in the model registry, along with corresponding unit tests. The review feedback suggests adjusting the default maximum output tokens for Claude from 64,000 to 8,192 to match actual model limits, and formatting the created_at field as an RFC 3339 datetime string instead of a Unix timestamp to align with the Anthropic API schema.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/registry/model_registry.go
Comment thread internal/registry/model_registry.go
Anthropic's List Models schema types created_at as an RFC 3339 datetime
string, but the Claude case of convertModelToMap emitted model.Created
as a Unix-timestamp integer. Format it with time.RFC3339 so the listing
matches the documented schema.
@luispater

Copy link
Copy Markdown
Collaborator

This endpoint is shared by OpenAI and Anthropic. You need to implement a mechanism to distinguish between them.

/v1/models is shared by the OpenAI and Anthropic surfaces and was
dispatched to the Claude format only for claude-cli User-Agents, so
generic Anthropic API clients received the OpenAI format. Distinguish
Anthropic requests by the Anthropic-Version header (sent by every
Anthropic client, never by OpenAI/Codex clients) in addition to the
existing claude-cli check, in both unifiedModelsHandler and
handleHomeModels. Additive and non-breaking for existing clients.
@dcrdev

dcrdev commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

This endpoint is shared by OpenAI and Anthropic. You need to implement a mechanism to distinguish between them.

I thought the change only affected the Claude path, but it sounds like you want the shared /v1/models endpoint to distinguish the two surfaces itself; so I've pushed a commit that routes Anthropic requests to the Claude format based on the Anthropic-Version header (in addition to the existing claude-cli check), applied in both unifiedModelsHandler and handleHomeModels. It's additive, so no existing OpenAI/Codex traffic changes path, and I've added tests for both the Anthropic-header case and the OpenAI-unaffected case.

@luispater luispater merged commit b0ca379 into router-for-me:dev Jun 20, 2026
3 checks passed
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.

[Bug] Claude /v1/models listing omits documented Anthropic schema field

2 participants