Skip to content

fix(router): wildcard order fallback to higher-order deployments - #25772

Merged
yuneng-berri merged 4 commits into
litellm_internal_stagingfrom
litellm_wildcard_order_fallback
Apr 22, 2026
Merged

fix(router): wildcard order fallback to higher-order deployments#25772
yuneng-berri merged 4 commits into
litellm_internal_stagingfrom
litellm_wildcard_order_fallback

Conversation

@Sameerlite

@Sameerlite Sameerlite commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • fix order-based fallback to use wildcard-aware deployment lookup, so wildcard model groups (for example openai/*) can advance from order=1 to higher order levels
  • preserve existing order fallback behavior for non-wildcard model groups
  • add a regression test that reproduces wildcard order fallback and validates routing to order=2
    Fixes LIT-2344

Test plan

  • poetry run pytest tests/test_litellm/test_router_order_fallback.py::test_router_order_fallback_with_wildcard_model_group -v
  • poetry run pytest tests/test_litellm/test_router_order_fallback.py -v
model_list:
  - model_name: "openai/*"
    litellm_params:
      model: "openai/*"
      api_base: "https://primary-gateway/v1"
      api_key: os.environ/OPENAI_API_KEY
      order: 1
  - model_name: "openai/*"
    litellm_params:
      model: "openai/*"
      api_base: "https://api.openai.com/v1"
      api_key: os.environ/OPENAI_API_KEY
      order: 2

router_settings:
  num_retries: 0

image Order 1: image Fallback(order 2): image

Use wildcard-aware deployment lookup when building order-based fallback levels so requests like openai/gpt-4.1-mini can advance from order=1 to order=2, and add a regression test for wildcard routing.

Made-with: Cursor
@vercel

vercel Bot commented Apr 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 15, 2026 0:20am

Request Review

@codspeed-hq

codspeed-hq Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing litellm_wildcard_order_fallback (9ed90d5) with main (72a461b)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes order-based fallback routing for wildcard model groups (e.g. openai/*) by replacing _get_all_deployments with get_model_list in the fallback handler. _get_all_deployments performs an exact index lookup and returns nothing for a specific model name like openai/gpt-4.1-mini when only openai/* is registered, causing the _order_set to be empty and order-level advancement to be silently skipped. get_model_list adds a pattern-router fallback that resolves the wildcard deployments and preserves their litellm_params.order values, enabling the existing order-fallback logic to build order=2 entries as expected. A regression test with mock responses validates the fix.

Confidence Score: 5/5

Safe to merge — targeted one-line fix with a clear regression test and no backward-incompatible changes.

The change is minimal and surgical: replacing _get_all_deployments with get_model_list (which itself calls _get_all_deployments first, then falls through to pattern routing). Exact-match model groups see identical behavior; wildcard groups gain the previously missing order-level advancement. The new test uses only mock responses and validates the end-to-end fix with a specific assertion. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
litellm/router.py Replaces _get_all_deployments with get_model_list (wildcard-aware) in the order-based fallback path; existing behavior for exact model groups is preserved since get_model_list calls _get_all_deployments first.
tests/test_litellm/test_router_order_fallback.py Adds a new asyncio test using mock_response (no real network calls) that registers two openai/* deployments at order=1 and order=2, triggers a failure on order=1, and asserts the response comes from the order=2 deployment.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[acompletion: model=openai/gpt-4.1-mini] --> B[Route to order=1 deployment]
    B --> C{Deployment fails?}
    C -- No --> D[Return response]
    C -- Yes --> E[Order-based fallback handler]
    E --> F["get_model_list(openai/gpt-4.1-mini)"]
    F --> G["_get_all_deployments → empty (no exact match)"]
    G --> H["pattern_router.route → finds openai/* deployments"]
    H --> I["_order_set = {1, 2}, order_values = [1, 2]"]
    I --> J["Build fallback: {model: openai/gpt-4.1-mini, _target_order: 2}"]
    J --> K["run_async_fallback with _target_order=2"]
    K --> L["Route to order=2 deployment"]
    L --> M[Return response]

    style G fill:#ffcccc
    style H fill:#ccffcc
Loading

Reviews (4): Last reviewed commit: "Merge branch 'litellm_internal_staging' ..." | Re-trigger Greptile

@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Sameerlite
Sameerlite changed the base branch from main to litellm_internal_staging April 15, 2026 16:52
@Sameerlite
Sameerlite temporarily deployed to integration-postgres April 21, 2026 03:49 — with GitHub Actions Inactive
@Sameerlite
Sameerlite temporarily deployed to integration-postgres April 21, 2026 03:49 — with GitHub Actions Inactive
@Sameerlite
Sameerlite temporarily deployed to integration-postgres April 21, 2026 03:49 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:08 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:08 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:08 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:50 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:50 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:50 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:50 — with GitHub Actions Inactive
@shivamrawat1
shivamrawat1 temporarily deployed to integration-postgres April 21, 2026 22:50 — with GitHub Actions Inactive
@yuneng-berri
yuneng-berri enabled auto-merge April 22, 2026 22:04
@yuneng-berri
yuneng-berri merged commit fb39683 into litellm_internal_staging Apr 22, 2026
100 of 101 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_wildcard_order_fallback branch April 22, 2026 22:05
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…fallback

fix(router): wildcard order fallback to higher-order deployments
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.

3 participants