diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.py index b7f35ef2304..6ee17c1f9d5 100644 --- a/litellm/proxy/health_endpoints/_health_endpoints.py +++ b/litellm/proxy/health_endpoints/_health_endpoints.py @@ -1256,8 +1256,11 @@ class _AccessGroupGrants: granted_names: frozenset[str] ids_in_granted_groups: frozenset[str] - def requested_name(self, name: str, public_names: Mapping[str, str]) -> str: - return name if name in self.granted_names else public_names.get(name, name) + def requested_name(self, name: str, public_names: Mapping[str, str], admitted_names: frozenset[str]) -> str: + public_name: Final = public_names.get(name) + if public_name is None or public_name not in admitted_names or name in self.granted_names: + return name + return public_name def narrow(self, serving_ids: frozenset[str], served_names: frozenset[str]) -> frozenset[str]: in_granted_groups: Final = serving_ids & self.ids_in_granted_groups @@ -1365,7 +1368,7 @@ async def _deployments_key_may_reach( access_group_grants: Final = _access_group_grants(llm_model_list, user_api_key_dict) public_names: Final = _public_names_by_internal_name(llm_model_list, user_api_key_dict.team_id) groups: Final = frozenset( - _served_group(access_group_grants.requested_name(name, public_names), aliases, llm_router) + _served_group(access_group_grants.requested_name(name, public_names, admitted_names), aliases, llm_router) for name in admitted_names ) ids_by_name: Final = _ids_by_requested_name(llm_model_list, user_api_key_dict.team_id) diff --git a/tests/unit/proxy/health_endpoints/test_health_endpoints.py b/tests/unit/proxy/health_endpoints/test_health_endpoints.py index 5ba7baabb12..a661f875345 100644 --- a/tests/unit/proxy/health_endpoints/test_health_endpoints.py +++ b/tests/unit/proxy/health_endpoints/test_health_endpoints.py @@ -4973,6 +4973,23 @@ async def test_health_endpoint_probes_a_team_deployment_whose_internal_name_the_ assert probed == {"id-team-premium", "id-team-standard"} +@pytest.mark.asyncio +async def test_health_endpoint_probes_only_the_team_deployment_whose_internal_name_an_agent_holds() -> None: + from litellm.types.agents import AgentResponse + + policy: Final = AgentResponse( + agent_id="managed", + agent_name="Managed", + agent_card_params={}, + object_permission={"models": ["model_name_team-a_9d2f6e01"]}, + ) + caller: Final = _team_key(["gpt-5.4-mini"]).model_copy(update={"managed_agent_policy": policy}) + + probed: Final = await _live_probed_model_ids(_team_split_model_list("gpt-5.4-mini", "openai/gpt-5.4-mini"), caller) + + assert probed == {"id-team-standard"} + + def test_resolve_targeted_model_ids_lets_model_id_win_over_model(): resolve = _health_endpoints_module._resolve_targeted_model_ids