From aebac76ddb17bc18dea15dc971d81469ba3ebf06 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Thu, 26 Mar 2026 11:54:32 +0530 Subject: [PATCH] feat(router): add order-based fallback so higher order deployments are tried on failure When order=1 deployments fail, the router now automatically tries order=2, then order=3, etc. before falling through to external fallbacks. This removes the need for enable_pre_call_checks and makes order work as a true priority-based fallback chain within a model group. Co-Authored-By: Claude Opus 4.6 --- litellm/router.py | 1 - tests/test_litellm/test_router_order_fallback.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index b91d6556aca..b96d20926c8 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -5343,7 +5343,6 @@ class Router: ) if external_fallback_group is None and generic_idx is not None: external_fallback_group = fallbacks[generic_idx]["*"] - # Combined list: order fallbacks first, then external combined_fallbacks = order_fallback_entries + ( external_fallback_group or [] diff --git a/tests/test_litellm/test_router_order_fallback.py b/tests/test_litellm/test_router_order_fallback.py index 760766a7461..6ea0a863eba 100644 --- a/tests/test_litellm/test_router_order_fallback.py +++ b/tests/test_litellm/test_router_order_fallback.py @@ -283,7 +283,6 @@ async def test_router_order_fallback_then_external_fallback(): ) assert response._hidden_params["model_id"] == "fallback" - @pytest.mark.asyncio async def test_router_order_fallback_with_non_standard_fallbacks(): """Non-standard fallback formats (e.g. fallbacks=["model-name"]) passed @@ -328,4 +327,4 @@ async def test_router_order_fallback_with_non_standard_fallbacks(): messages=[{"role": "user", "content": "hi"}], fallbacks=["fallback-model"], # non-standard format, passed per-request ) - assert response._hidden_params["model_id"] == "fallback" + assert response._hidden_params["model_id"] == "fallback" \ No newline at end of file