Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6803894
test(proxy): cover /health scoping for wildcard keys and team model a…
mateo-berri Oct 21, 2026
3c862ef
fix(proxy): scope /health with the model access check auth runs on a …
mateo-berri Oct 21, 2026
f2604b1
Merge remote-tracking branch 'origin/main' into litellm_health_scope_…
mateo-berri Oct 28, 2026
4f15b37
fix(proxy): scope /health to the model group an allowed name routes to
mateo-berri Oct 28, 2026
e9e7607
test(proxy): cover /health skipping a deployment that has no model na…
mateo-berri Oct 28, 2026
8d9eab0
fix(health): show deployments reached through wildcard and alias allo…
mateo-berri Oct 29, 2026
cfd8dd5
Merge remote-tracking branch 'origin/main' into litellm_health_scope_…
mateo-berri Oct 29, 2026
7fe9c7c
chore(router): drop should_include_deployment from the outside-use al…
mateo-berri Oct 29, 2026
db8bcc9
Merge remote-tracking branch 'origin/main' into litellm_health_scope_…
mateo-berri Oct 29, 2026
6729084
Merge remote-tracking branch 'origin/main' into litellm_health_scope_…
mateo-berri Oct 29, 2026
aeda237
fix(health): never list a default-fallback deployment for an unserved…
mateo-berri Oct 29, 2026
534227a
fix(health): resolve ?model= through the caller's aliases the way cha…
mateo-berri Oct 29, 2026
18363ba
fix(proxy): apply user and agent model limits to /health and yield be…
mateo-berri Oct 29, 2026
c6f1dce
fix(proxy): check owner and agent grants for wildcard routes in /heal…
mateo-berri Oct 29, 2026
5166ba9
fix(proxy): answer /health auth lookup failures the way chat does and…
mateo-berri Oct 29, 2026
47c5569
Merge remote-tracking branch 'origin/main' into litellm_health_scope_…
mateo-berri Oct 29, 2026
23377f3
test(proxy): pass recorded_model_name in the direct health save tests
mateo-berri Oct 29, 2026
49efac1
Merge remote-tracking branch 'origin/main' into litellm_health_scope_…
mateo-berri Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions litellm/proxy/auth/auth_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
UserAPIKeyAuth,
)
from litellm.proxy.agent_endpoints.auth.agent_access_groups import (
AgentAccessGroupCeiling,
CeilingResolver,
resolve_agent_access_group_ceiling,
)
Expand Down Expand Up @@ -1680,6 +1681,7 @@ def get_actual_routes(allowed_routes: list) -> list:

KEY_END_USER_BUDGET_ID_METADATA_FIELD: Final = "end_user_budget_id"
_KEY_METADATA_ADAPTER: Final[TypeAdapter[Mapping[str, object] | None]] = TypeAdapter(Mapping[str, object] | None)
_OBJECTS_ADAPTER: Final[TypeAdapter[tuple[object, ...]]] = TypeAdapter(tuple[object, ...])


def get_key_end_user_budget_id(key_metadata: Mapping[str, object] | None) -> str | None:
Expand Down Expand Up @@ -5081,27 +5083,46 @@ async def can_agent_call_model(
)


async def _agent_access_group_ceilings(
valid_token: UserAPIKeyAuth, resolve_ceiling: CeilingResolver
) -> tuple[AgentAccessGroupCeiling, ...]:
if not valid_token.agent_id:
return ()

from litellm.proxy.agent_endpoints.auth.agent_access_groups import resolve_managed_agent_ceilings

managed: Final = managed_agent_policy(valid_token)
if managed is not None:
return await resolve_managed_agent_ceilings(managed)
unmanaged: Final = await resolve_ceiling(valid_token.agent_id)
return (unmanaged,) if unmanaged is not None else ()


def _managed_agent_model_grants(valid_token: UserAPIKeyAuth) -> frozenset[str]:
managed: Final = managed_agent_policy(valid_token)
granted: Final = (managed.object_permission or {}).get("models") if managed is not None else None
if not isinstance(granted, (list, tuple)):
return frozenset()
return frozenset(name for name in _OBJECTS_ADAPTER.validate_python(granted) if isinstance(name, str))


async def agent_model_grants(
valid_token: UserAPIKeyAuth, resolve_ceiling: CeilingResolver = resolve_agent_access_group_ceiling
) -> frozenset[str]:
ceilings: Final = await _agent_access_group_ceilings(valid_token, resolve_ceiling)
return _managed_agent_model_grants(valid_token).union(*(ceiling.models for ceiling in ceilings))


async def _check_agent_access_group_model_access(
model: str | list[str] | None, # mutable-ok: _can_object_call_model and the client message helper take list[str]
valid_token: UserAPIKeyAuth | None,
llm_router: Router | None,
resolve_ceiling: CeilingResolver = resolve_agent_access_group_ceiling,
) -> Literal[True]:
"""Attached groups naming no model deny every model; the empty allowlist in ``_can_object_call_model`` allows."""
if not model or valid_token is None or not valid_token.agent_id:
if not model or valid_token is None:
return True

from litellm.proxy.agent_endpoints.auth.agent_access_groups import resolve_managed_agent_ceilings

managed: Final = managed_agent_policy(valid_token)
unmanaged: Final = await resolve_ceiling(valid_token.agent_id) if managed is None else None
ceilings: Final = (
await resolve_managed_agent_ceilings(managed)
if managed is not None
else (unmanaged,)
if unmanaged is not None
else ()
)
ceilings: Final = await _agent_access_group_ceilings(valid_token, resolve_ceiling)
dispatched: Final = _resolve_team_alias(
model, team_model_aliases_for_auth_check(valid_token), valid_token.team_id, llm_router
)
Expand Down
6 changes: 4 additions & 2 deletions litellm/proxy/auth/auth_exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
Span = Any


def _as_proxy_exception(e: Exception) -> ProxyException:
def auth_failure_as_proxy_exception(e: Exception) -> ProxyException:
"""Convert an authentication failure into the ProxyException the client receives."""
if isinstance(e, litellm.BudgetExceededError):
return ProxyException(
Expand Down Expand Up @@ -262,7 +262,9 @@ async def handle_authentication_error(
if transformed_exception is not None:
e = transformed_exception

final_exception: Final = mark_invalid_virtual_key_error(_as_proxy_exception(e), is_invalid_virtual_key)
final_exception: Final = mark_invalid_virtual_key_error(
auth_failure_as_proxy_exception(e), is_invalid_virtual_key
)
# If a quiet-logged malformed-key transform yields non-401, escalate to ERROR
if is_quiet_log and str(final_exception.code) != str(status.HTTP_401_UNAUTHORIZED):
verbose_proxy_logger.error(
Expand Down
7 changes: 6 additions & 1 deletion litellm/proxy/common_utils/model_listing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def caller_alias_maps(

def alias_map(aliases: object) -> Mapping[str, str]:
try:
entries: Final = _ALIAS_ENTRIES.validate_python(aliases, strict=True)
entries: Final = _ALIAS_ENTRIES.validate_python(aliases)
except ValidationError:
return _NO_ALIASES
return MappingProxyType(
Expand Down Expand Up @@ -287,6 +287,11 @@ def _dispatch(model_id: str, layers: Sequence[_AliasLayer]) -> tuple[str, bool]:
return reduce(_through_layer, layers, (model_id, False))


def dispatched_model(model_id: str, aliases: CallerAliases) -> str:
target, _ = _dispatch(model_id, _alias_layers(aliases))
return target


def _lookup_id(name: str, lookup_by_response: Mapping[str, str], lookup_ids: Container[str]) -> str | None:
if name in lookup_by_response:
return lookup_by_response[name]
Expand Down
Loading
Loading