fix(proxy): resolve a key or team group alias in auth for Ask AI

This commit is contained in:
mateo-berri 2026-10-20 06:29:15 -07:00
parent 1e2e235653
commit b31234e3c0
2 changed files with 14 additions and 2 deletions

View file

@ -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

View file

@ -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