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.
This commit is contained in:
PRABHU KIRAN VANDRANKI 2026-05-22 11:51:19 -04:00
parent f69b9d6564
commit a2f9963a1d

View file

@ -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,