Skip to content

server: implement GET /v1/models for gateway model discovery#61

Merged
raine merged 1 commit into
raine:mainfrom
kevinsslin:feat/v1-models-endpoint
Jul 20, 2026
Merged

server: implement GET /v1/models for gateway model discovery#61
raine merged 1 commit into
raine:mainfrom
kevinsslin:feat/v1-models-endpoint

Conversation

@kevinsslin

Copy link
Copy Markdown
Contributor

Fixes #60.

Problem

The README quickstart recommends CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1, but there is no /v1/models route, so Claude Code's startup discovery request (GET /v1/models?limit=1000) falls through and the flag silently does nothing.

Change

Single concern: add GET /v1/models, serving the registry's model list in the Anthropic models-list shape.

  • data[].id + data[].display_name ("<model> (<provider>)") + type: "model"
  • has_more, first_id, last_id; limit honored, unknown query params tolerated
  • The Anthropic-style aliases from the registry are included. Per the official gateway protocol (https://code.claude.com/docs/en/llm-gateway-protocol), Claude Code ignores discovered ids that don't start with claude/anthropic, so the aliases are what actually surface in the /model picker; raw provider ids remain listed for other Anthropic-compatible clients.
  • No auth on the endpoint, matching the server's existing no-inbound-auth posture; response is static registry data (fits Claude Code's 3s discovery timeout, no redirects).

Testing

  • 4 new integration tests in tests/server.rs (list shape, claude-prefixed aliases present, limit + has_more, unknown query params tolerated)
  • cargo test: 599 passed, 0 failed
  • cargo fmt --all --check clean
  • cargo clippy --all-targets -- -D warnings: identical pre-existing error count before/after (34), none in touched files
  • Live check on a local build:
$ curl -s 'http://127.0.0.1:18799/v1/models?limit=1000' | jq '[.data[].id | select(startswith("claude-"))]'
["claude-fable-5","claude-haiku-4-5","claude-haiku-4-5-20251001","claude-opus-4-7","claude-opus-4-8","claude-sonnet-4-6","claude-sonnet-5"]

The README quickstart recommends CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1,
but the router has no /v1/models route, so Claude Code's startup discovery
request 404s and the flag silently does nothing.

Serve the registry's full model list in the Anthropic models-list shape
(data[].id/display_name, has_more, first_id/last_id, limit honored). The
Anthropic-style aliases (claude-sonnet-5 etc.) are included, which matters
because Claude Code only adds discovered ids starting with claude/anthropic
to its /model picker; raw provider ids are still listed for other clients.
@raine
raine merged commit 7967fe3 into raine:main Jul 20, 2026
@raine

raine commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Thank you

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.

CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 in the README does nothing: /v1/models is not implemented

2 participants