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
feat: Add /global/spend/tags to admin viewer routes (#17501)
Ishaan Jaffe3116da653c7
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.pyindex 53a8627bc8f..4412466a169 100644--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@ -511,6 +511,7 @@ class LiteLLMRoutes(enum.Enum):"/global/predict/spend/logs","/global/spend/report","/global/spend/provider",+ "/global/spend/tags",]public_routes = set(@@ -547,6 +548,7 @@ class LiteLLMRoutes(enum.Enum):"/global/spend/logs","/global/spend/keys","/global/spend/models",+ "/global/spend/tags","/global/predict/spend/logs","/global/activity","/health/services",diff --git a/litellm/proxy/auth/route_checks.py b/litellm/proxy/auth/route_checks.pyindex 76621e95cd3..aaef2103ad9 100644--- a/litellm/proxy/auth/route_checks.py+++ b/litellm/proxy/auth/route_checks.py@@ -608,6 +608,12 @@ class RouteChecks:):# Allow access to admin viewer routes (read-only admin endpoints)return+ elif RouteChecks.check_route_access(+ route=route, allowed_routes=LiteLLMRoutes.global_spend_tracking_routes.value+ ):+ # Allow access to global spend tracking routes (read-only spend endpoints)+ # proxy_admin_viewer role description: "view all keys, view all spend"+ returnelse:# For other routes, block accessraise HTTPException(diff --git a/tests/test_litellm/proxy/auth/test_route_checks.py b/tests/test_litellm/proxy/auth/test_route_checks.pyindex de2aa2427ca..f9276645a58 100644--- a/tests/test_litellm/proxy/auth/test_route_checks.py+++ b/tests/test_litellm/proxy/auth/test_route_checks.py@@ -759,4 +759,49 @@ def test_non_proxy_admin_wildcard_allowed_routes():valid_token=valid_token,request_data={},)+++def test_proxy_admin_viewer_can_access_global_spend_tags():+ """+ Test that proxy_admin_viewer can access /global/spend/tags endpoint.++ This test verifies the fix for the issue where proxy_admin_viewer was getting+ 403 errors when trying to access /global/spend/tags endpoint.++ Related: Slack thread from 10/9/2025 - Erik Kristensen reported this issue.+ proxy_admin_viewer role should have access to "view all spend" endpoints.+ """++ # Create a proxy admin viewer user object+ user_obj = LiteLLM_UserTable(+ user_id="viewer_user",+ user_email="[email protected]",+ user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value,+ )++ # Create a proxy admin viewer user API key auth+ valid_token = UserAPIKeyAuth(+ user_id="viewer_user",+ user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value,+ )++ # Create a mock request+ request = MagicMock(spec=Request)+ request.query_params = {"start_date": "2025-05-12", "end_date": "2025-10-09"}++ # Test that calling /global/spend/tags route does NOT raise an exception+ try:+ RouteChecks.non_proxy_admin_allowed_routes_check(+ user_obj=user_obj,+ _user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value,+ route="/global/spend/tags",+ request=request,+ valid_token=valid_token,+ request_data={},+ )+ # If no exception is raised, the test passes+ except Exception as e:+ pytest.fail(+ f"proxy_admin_viewer should be able to access /global/spend/tags route. Got error: {str(e)}"+ )