Skip to content

feat: extended /v1/models endpoint, now it returns with fallbacks on demand #12811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 23, 2025

Conversation

murad-khafizov
Copy link
Contributor

Type

🆕 New Feature

Changes

Summary

Enhanced the existing /v1/models endpoint to include complete
fallback information for models while maintaining full backward
compatibility. This enables clients to discover all available
fallbacks for each model based on the router's fallback
configuration.

Key Features

  • New Query Parameters:
    • include_metadata: bool = False - Include additional metadata
      in response
    • fallback_type: Optional[str] = None - Specify fallback type
      (defaults to "general")
  • Complete Fallback Lists: Returns all configured fallbacks for
    each model, not just the next one
  • Three Fallback Types: Supports general, context_window,
    and content_policy fallbacks
  • Backward Compatible: Existing /v1/models calls work
    unchanged
  • Generic Metadata Structure: Extensible for future
    enhancements

Implementation Details

Core Function (litellm/proxy/auth/model_checks.py)

def get_all_fallbacks(
    model: str,
    llm_router: Optional[Router] = None,
    fallback_type: str = "general",
) -> List[str]:
- Leverages existing get_fallback_model_group() function
- Handles all three fallback types from router configuration
- Returns complete fallback list for specified model
- Graceful error handling with empty list fallback

Enhanced Endpoint (litellm/proxy/proxy_server.py)

- Added new optional query parameters to model_list() function
- Defaults to "general" fallback type when include_metadata=true
- Proper parameter validation with HTTP 400 for invalid types
- Maintains OpenAI-compatible response format

API Usage Examples

# Standard response (backward compatible)
GET /models

# Include metadata with general fallbacks (default)
GET /models?include_metadata=true

# Include specific fallback types
GET /models?include_metadata=true&fallback_type=context_window
GET /models?include_metadata=true&fallback_type=content_policy

Response Format

Standard Response (unchanged):
{
  "data": [
    {
      "id": "claude-4-sonnet",
      "object": "model",
      "created": 1234567890,
      "owned_by": "openai"
    }
  ],
  "object": "list"
}

With Fallback Metadata:
{
  "data": [
    {
      "id": "claude-4-sonnet",
      "object": "model",
      "created": 1234567890,
      "owned_by": "openai",
      "metadata": {
        "fallbacks": ["bedrock-claude-sonnet-4",
"google-claude-sonnet-4"]
      }
    }
  ],
  "object": "list"
}
image

Copy link

vercel bot commented Jul 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 0:20am

@krrishdholakia
Copy link
Contributor

Nice feature! @murad-khafizov

@krrishdholakia krrishdholakia merged commit a6ddf5c into BerriAI:main Jul 23, 2025
6 checks passed
@krrishdholakia
Copy link
Contributor

would be great to document this somewhere. Maybe under model access? https://docs.litellm.ai/docs/proxy/model_access

open to your thoughts on this.

satendrakumar pushed a commit to satendrakumar/litellm that referenced this pull request Jul 24, 2025
…n demand (BerriAI#12811)

* Extended `/v1/model` endpoint to support fallbacks

* unit tests reworked

* linting fixes

* fix lining error

* fix linting
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.

2 participants