litellm - 💡(How to fix) Fix [Feature]: Support Anthropic-native response format for /v1/models endpoint (Claude Code gateway discovery) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#27180Fetched 2026-05-06 06:15:43
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×2commented ×1

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.

Root Cause

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.

Code Example

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

---

{
  "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"
}
RAW_BUFFERClick to expand / collapse

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.

extent analysis

TL;DR

Implement content negotiation or a separate endpoint to return the Anthropic-format response for the /v1/models endpoint in LiteLLM.

Guidance

  • Consider adding a header-based content negotiation to return the Anthropic format when the anthropic-version header is present in the request.
  • Alternatively, introduce a separate endpoint, such as /anthropic/v1/models, to serve the Anthropic-format response.
  • Evaluate the feasibility of adding a config option, like model_list_format: anthropic, to switch the response format globally for the /v1/models endpoint.
  • Verify that the chosen approach correctly populates the /model picker with discovered models labeled "From gateway" in Claude Code.

Example

// Example of Anthropic-format response
{
  "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"
}

Notes

The proposed solution focuses on modifying the LiteLLM /v1/models endpoint to return the Anthropic-format response. This may require updates to the LiteLLM API and potentially its documentation.

Recommendation

Apply a workaround by implementing content negotiation to return the Anthropic-format response when the anthropic-version header is present. This approach allows for a more seamless integration with Claude Code without requiring significant changes to the existing API endpoints.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING