Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(router): only resolve structured input when messages is absent

mateo-berri791b478d775e
diff --git a/litellm/router_strategy/auto_router/auto_router.py b/litellm/router_strategy/auto_router/auto_router.py
index 86383a27880..c77745a498d 100644
--- a/litellm/router_strategy/auto_router/auto_router.py
+++ b/litellm/router_strategy/auto_router/auto_router.py
@@ -134,7 +134,11 @@ class AutoRouter(CustomLogger):
)
from litellm.types.router import PreRoutingHookResponse
- resolved_messages: Final = resolve_structured_messages(messages=messages, request_kwargs=request_kwargs)
+ resolved_messages: Final = (
+ messages
+ if messages is not None
+ else resolve_structured_messages(messages=None, request_kwargs=request_kwargs)
+ )
if resolved_messages is None:
return None
diff --git a/tests/test_litellm/router_strategy/test_auto_router.py b/tests/test_litellm/router_strategy/test_auto_router.py
index 10d133e7311..c71a6b0e27f 100644
--- a/tests/test_litellm/router_strategy/test_auto_router.py
+++ b/tests/test_litellm/router_strategy/test_auto_router.py
@@ -546,3 +546,18 @@ class TestAutoRouterRoutesResponsesApiInput:
assert result is None
assert layer.seen_text is None
+
+ @pytest.mark.asyncio
+ async def test_should_keep_routing_an_empty_messages_list_to_the_default_model(self):
+ layer: Final = FixedRouteLayer(None)
+ auto_router: Final = _auto_router(layer)
+
+ result: Final = await auto_router.async_pre_routing_hook(
+ model="my-auto-router",
+ request_kwargs={"messages": [], "litellm_metadata": {"user_api_key_request_route": "/v1/chat/completions"}},
+ messages=[],
+ )
+
+ assert result is not None
+ assert result.model == "fallback-model"
+ assert layer.seen_text == ""