From f49836dd4c6561c404c609b28a44dffcfa1f7e0b Mon Sep 17 00:00:00 2001 From: Shin Date: Sat, 7 Feb 2026 20:13:13 +0000 Subject: [PATCH] fix(proxy): only create Router when models or search_tools exist Previously, PR #19818 (via #20205) removed the model_list check entirely, causing Router to be created even with no models AND no search_tools. This fix adds back a conditional check that creates the Router only when: - There are models to route, OR - There are search_tools configured This preserves the PR #19818 goal (search-tools-only deployments) while avoiding unnecessary Router creation when there's nothing to route. Fixes test_add_and_delete_deployments[0-None] --- litellm/proxy/proxy_server.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index cf9e00512b1..22d63579986 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -3249,18 +3249,19 @@ async def _update_llm_router( _model_list: list = self.decrypt_model_list_from_db( new_models=models_list ) - # Create router even with empty model list to support search_tools - # Router can function with model_list=[] and only search_tools - verbose_proxy_logger.debug(f"_model_list: {_model_list}") - llm_router = litellm.Router( - model_list=_model_list, - router_general_settings=RouterGeneralSettings( - async_only_mode=True # only init async clients - ), - search_tools=search_tools, - ignore_invalid_deployments=True, - ) - verbose_proxy_logger.debug(f"updated llm_router: {llm_router}") + # Only create router if we have models or search_tools to route + # Router can function with model_list=[] if search_tools are configured + if len(_model_list) > 0 or search_tools: + verbose_proxy_logger.debug(f"_model_list: {_model_list}") + llm_router = litellm.Router( + model_list=_model_list, + router_general_settings=RouterGeneralSettings( + async_only_mode=True # only init async clients + ), + search_tools=search_tools, + ignore_invalid_deployments=True, + ) + verbose_proxy_logger.debug(f"updated llm_router: {llm_router}") else: verbose_proxy_logger.debug(f"len new_models: {len(models_list)}") if search_tools is not None and llm_router is not None: