From a2f9963a1d38ddb8afad8b59b4d143fe6b278447 Mon Sep 17 00:00:00 2001 From: PRABHU KIRAN VANDRANKI <72809214+VANDRANKI@users.noreply.github.com> Date: Fri, 22 May 2026 11:51:19 -0400 Subject: [PATCH] fix(router): call async_pre_routing_hook in non-async routing strategy fallback path Fixes #26224: complexity_router and other auto-routers that rely on async_pre_routing_hook to resolve router model names were silently bypassed when the default (non-async) routing strategy was active. The async_get_available_deployment function falls back to the sync get_available_deployment for routing strategies that don't have an async implementation. This fallback skipped async_pre_routing_hook entirely, so the model name was never resolved from the router alias (e.g. 'smart-router') to the actual downstream model (e.g. 'claude-sonnet-4-6'), causing downstream errors like 'unknown model auto_router/complexity_router'. Fix: call async_pre_routing_hook before get_available_deployment in the sync fallback path so the model is properly resolved regardless of routing strategy. --- litellm/router.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/litellm/router.py b/litellm/router.py index 9185e437a3a..73ee37c243e 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -9317,6 +9317,20 @@ class Router: and self.routing_strategy != "latency-based-routing" and self.routing_strategy != "least-busy" ): # prevent regressions for other routing strategies, that don't have async get available deployments implemented. + # Run async pre-routing hooks (e.g. complexity_router) so that router + # model names are resolved to the correct downstream model before + # deployment selection, even when a non-async routing strategy is used. + pre_routing_hook_response = await self.async_pre_routing_hook( + model=model, + request_kwargs=request_kwargs, + messages=messages, + input=input, + specific_deployment=specific_deployment, + ) + if pre_routing_hook_response is not None: + model = pre_routing_hook_response.model + if pre_routing_hook_response.messages is not None: + messages = pre_routing_hook_response.messages return self.get_available_deployment( model=model, messages=messages,