The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/main' into litellm_model_access_denied_message
yassin5fee1c87104b
diff --cc litellm/proxy/auth/handle_jwt.pyindex 0389f69cfeb,4fe44eb1dc8..6a28cd7ff99--- a/litellm/proxy/auth/handle_jwt.py+++ b/litellm/proxy/auth/handle_jwt.py@@@ -52,13 -53,9 +53,13 @@@ from litellm.proxy._types importUserAPIKeyAuth,)from litellm.proxy.auth.auth_checks import can_team_access_model+from litellm.proxy.auth.model_access_denied import (+ ModelAccessDeniedHTTPException,+ model_access_denied_client_message,+)from litellm.proxy.auth.resolvers.grants import GrantResolver, UserLookup, canonical_user_idfrom litellm.proxy.auth.route_checks import RouteChecks- from litellm.proxy.auth.team_grants import team_model_aliases+ from litellm.proxy.auth.team_grants import team_grants, team_model_aliasesfrom litellm.proxy.common_utils.user_api_key_cache import (UserApiKeyCache,get_management_object_ttl,diff --cc tests/test_litellm/proxy/auth/test_handle_jwt.pyindex a8385eadc59,6fbbb37fbc3..a6d5dc007a8--- a/tests/test_litellm/proxy/auth/test_handle_jwt.py+++ b/tests/test_litellm/proxy/auth/test_handle_jwt.py@@@ -6972,42 -7067,34 +7072,77 @@@ async def test_auth_builder_denies_jwt_assert exc_info.value.status_code == 403+_JWT_DENIED_CLIENT_MESSAGE = (+ "The requested model 'gpt-5.6' is not available for this API key, or the model name is invalid. "+ "Check the models available to you and try again."+)+++def test_can_rbac_role_call_model_denial_hides_role_allowlist_from_client():+ general_settings = {+ "role_permissions": [+ RoleBasedPermissions(role=LitellmUserRoles.INTERNAL_USER, models=["gpt-5.6-mini"]),+ ]+ }++ with pytest.raises(ModelAccessDeniedHTTPException) as exc_info:+ JWTAuthManager.can_rbac_role_call_model(+ rbac_role=LitellmUserRoles.INTERNAL_USER,+ general_settings=general_settings,+ model="gpt-5.6",+ )++ assert exc_info.value.status_code == 403+ assert exc_info.value.detail == _JWT_DENIED_CLIENT_MESSAGE+ assert exc_info.value.internal_message == (+ "Role=internal_user not allowed to call model=gpt-5.6. Allowed models=['gpt-5.6-mini']"+ )+++def test_check_scope_based_access_denial_hides_scope_allowlist_from_client():+ with pytest.raises(ModelAccessDeniedHTTPException) as exc_info:+ JWTAuthManager.check_scope_based_access(+ scope_mappings=[ScopeMapping(scope="litellm.api.consumer", models=["gpt-5.6-mini"])],+ scopes=["litellm.api.consumer"],+ request_data={"model": "gpt-5.6"},+ general_settings={},+ )++ assert exc_info.value.status_code == 403+ assert exc_info.value.detail == {"error": _JWT_DENIED_CLIENT_MESSAGE}+ assert exc_info.value.internal_message == "model=gpt-5.6 not allowed. Allowed_models=['gpt-5.6-mini']"++||||||| 24153b5f29++=======+++++ @pytest.mark.asyncio+ @pytest.mark.parametrize("admission", [False, True])+ async def test_admin_jwt_team_header_only_provisions_during_admission(monkeypatch, admission: bool):+ from litellm.proxy.management_endpoints import team_endpoints++ handler, token = _entra_signed_app_token(+ monkeypatch, azp="canonical-agent-id", scope=LiteLLM_JWTAuth().admin_jwt_scope,+ )+ handler.bind_agent_lookup(_entra_agent_registry())+ handler.litellm_jwtauth.team_id_upsert = True+ handler.litellm_jwtauth.admin_allowed_routes = ["openai_routes"]+ database = MagicMock()+ database.db.litellm_teamtable.find_unique = AsyncMock(return_value=None)+ create_team = AsyncMock(return_value=LiteLLM_TeamTable(team_id="new-team").model_dump())+ monkeypatch.setattr(team_endpoints, "new_team", create_team)+ resolve = JWTAuthManager.auth_builder if admission else JWTAuthManager.authorize_jwt++ result = await resolve(+ api_key=token, jwt_handler=handler, request_data={}, general_settings={},+ route="/chat/completions", prisma_client=database,+ user_api_key_cache=handler.user_api_key_cache, parent_otel_span=None,+ proxy_logging_obj=MagicMock(), request_headers={"x-litellm-team-id": "new-team"},+ )++ assert result["is_proxy_admin"] is True+ if admission:+ create_team.assert_awaited_once()+ assert result["team_id"] == "new-team"+ else:+ create_team.assert_not_awaited()+ assert result["team_id"] is None