diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index a1abed202a2..56a0fe6d8b3 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -268,6 +268,7 @@ _CLAUDE_MODEL_ROUTES: Final = frozenset( f"/{prefix}{endpoint}" for prefix in ("", "v1/") for endpoint in ("messages", "chat/completions", "responses") ) _CLAUDE_MODEL_NORMALIZED: Final = "litellm.claude_model_normalized" +_USAGE_AI_CHAT_ROUTE: Final = "/usage/ai/chat" async def _normalize_claude_model( @@ -298,6 +299,10 @@ async def _normalize_claude_model( rewrite_request_model(request_data, request, source) +def _routes_through_router(route: str) -> bool: + return RouteChecks.is_llm_api_route(route=route) or route == _USAGE_AI_CHAT_ROUTE + + async def _resolve_router_settings_model_group_alias( request_data: dict[str, object], # mutable-ok: the request body is rewritten in place for every downstream reader valid_token: UserAPIKeyAuth, @@ -309,7 +314,7 @@ async def _resolve_router_settings_model_group_alias( """ from litellm.proxy.proxy_server import llm_router, prisma_client, proxy_config, proxy_logging_obj - if request is None or llm_router is None or not RouteChecks.is_llm_api_route(route=route): + if request is None or llm_router is None or not _routes_through_router(route): return if request.scope.get(MODEL_GROUP_ALIAS_RESOLVED_SCOPE_KEY) is True: return diff --git a/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py b/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py index 4cdd7fefd28..b98a187eeb4 100644 --- a/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py +++ b/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py @@ -11719,7 +11719,14 @@ def _alias_token(monkeypatch, level: str, alias: dict, models: list) -> UserAPIK @pytest.mark.parametrize("level", ["key", "team"]) @pytest.mark.parametrize( "route", - ["/v1/chat/completions", "/v1/messages", "/v1/embeddings", "/openai/v1/responses", "/cursor/chat/completions"], + [ + "/v1/chat/completions", + "/v1/messages", + "/v1/embeddings", + "/openai/v1/responses", + "/cursor/chat/completions", + "/usage/ai/chat", + ], ) async def test_router_settings_model_group_alias_authorizes_target_for_key(monkeypatch, level, route): """LIT-3054: a key allowed only the alias target must be able to call the alias, and a key not