diff --git a/litellm/router.py b/litellm/router.py index 914a9f04a05..7fa5694c0ae 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -10053,8 +10053,8 @@ class Router: if len(team_ids) > 1: raise litellm.BadRequestError( message=( - f"Team-scoped model name '{model}' is configured for multiple teams. " - "Pass a team context or deployment ID to select one." + f"Model name '{model}' matches deployments from multiple teams. " + "Specify the deployment ID directly to disambiguate." ), model=model, llm_provider="", diff --git a/litellm/router_utils/common_utils.py b/litellm/router_utils/common_utils.py index f1fa524871d..0583ccddd1e 100644 --- a/litellm/router_utils/common_utils.py +++ b/litellm/router_utils/common_utils.py @@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Union if TYPE_CHECKING: from litellm.types.llms.openai import OpenAIFileObject +from litellm.exceptions import BadRequestError from litellm.types.router import CredentialLiteLLMParams from litellm._logging import verbose_logger @@ -78,6 +79,25 @@ def filter_team_based_models( candidate_model_info = tuple( model_info for deployment in healthy_deployments for model_info in [deployment.get("model_info") or {}] ) + team_ids = frozenset( + team_id + for model_info in candidate_model_info + for team_id in [model_info.get("team_id")] + if team_id is not None + ) + if ( + isinstance(requested_model, str) + and len(team_ids) > 1 + and all(model_info.get("team_public_model_name") == requested_model for model_info in candidate_model_info) + ): + raise BadRequestError( + message=( + f"Model name '{requested_model}' matches deployments from multiple teams. " + "Specify the deployment ID directly to disambiguate." + ), + model=requested_model, + llm_provider="", + ) if ( isinstance(requested_model, str) and candidate_model_info diff --git a/tests/test_litellm/proxy/test_route_llm_request.py b/tests/test_litellm/proxy/test_route_llm_request.py index f03e9d06fe6..2bd795fa745 100644 --- a/tests/test_litellm/proxy/test_route_llm_request.py +++ b/tests/test_litellm/proxy/test_route_llm_request.py @@ -167,6 +167,29 @@ async def test_route_request_proxy_admin_can_call_all_team_scoped_deployments_wi }, ) ) + router.add_deployment( + Deployment( + model_name="team-azure", + litellm_params={ + "model": "azure/gpt-4o", + "api_key": "fake", + "api_base": "https://other-legacy.example.openai.azure.com", + "api_version": "2024-02-15-preview", + }, + model_info={ + "id": "other-legacy-team-azure", + "team_id": "team-b", + "team_public_model_name": "team-azure", + }, + ) + ) + + with pytest.raises(litellm.BadRequestError, match="multiple teams"): + await router.async_get_healthy_deployments( + model="team-azure", + request_kwargs=data, + ) + router.add_deployment( Deployment( model_name="team-azure",