Skip to content

[Feature]: Support Anthropic-native response format for /v1/models endpoint (Claude Code gateway discovery) #27180

Description

@odinwang

Feature Request

Summary

Claude Code 2.1.126+ added gateway model discovery: when ANTHROPIC_BASE_URL points at a compatible gateway, it queries {base_url}/v1/models at startup and populates the /model picker with discovered models labeled "From gateway".

However, this discovery only works with the Anthropic-native /v1/models response format — it does not parse the OpenAI-format response that LiteLLM currently returns.

Current Behavior

LiteLLM's /v1/models returns OpenAI format:

{
  "data": [
    {
      "id": "claude-opus-4-6",
      "object": "model",
      "created": 1677610602,
      "owned_by": "openai"
    }
  ],
  "object": "list"
}

Expected Behavior

Claude Code expects the Anthropic native format:

{
  "data": [
    {
      "type": "model",
      "id": "claude-opus-4-6",
      "display_name": "Claude Opus 4.6",
      "created_at": "2025-05-14T00:00:00Z"
    }
  ],
  "has_more": false,
  "first_id": "claude-opus-4-6",
  "last_id": "claude-haiku-4-5"
}

Key differences:

  • type: "model" instead of object: "model"
  • display_name field (used as label in the picker)
  • created_at (ISO 8601) instead of created (unix timestamp)
  • Top-level has_more, first_id, last_id instead of object: "list"

Claude Code's Discovery Filter

From the docs:

Only models whose ID begins with claude or anthropic are added to the picker. Results are cached to ~/.claude/cache/gateway-models.json.

Authentication: sends x-api-key header (or Bearer token via ANTHROPIC_AUTH_TOKEN), same as inference requests.

Proposed Solution

Since LiteLLM already supports the Anthropic /v1/messages pass-through endpoint for Claude Code users, adding an Anthropic-format response option for /v1/models would complete the compatibility story. Possible approaches:

  1. Content negotiation: Return Anthropic format when the request includes anthropic-version header (same header Claude Code sends for /v1/messages)
  2. Separate endpoint: Serve Anthropic-format at /anthropic/v1/models (similar to the existing /anthropic pass-through path)
  3. Config option: A setting like model_list_format: anthropic to switch the /v1/models response format globally

Environment

  • LiteLLM version: latest stable (deployed on EKS)
  • Claude Code version: 2.1.128
  • Config: Using ANTHROPIC_BASE_URL pointing to LiteLLM proxy root, with /v1/messages working correctly

Additional Context

The gateway model discovery feature was added in Claude Code 2.1.126 changelog. Many Claude Code + LiteLLM users would benefit from this since it enables seamless model switching without manual configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions