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
fix(proxy): reject throttled exhausted budgets in JEV previews
Moe Khalil3b0d32ec6f14
diff --git a/litellm/proxy/management_endpoints/auto_router_endpoints.py b/litellm/proxy/management_endpoints/auto_router_endpoints.pyindex f79425d2e97..c5a10cf5c80 100644--- a/litellm/proxy/management_endpoints/auto_router_endpoints.py+++ b/litellm/proxy/management_endpoints/auto_router_endpoints.py@@ -345,6 +345,14 @@ async def _authorize_models_this_test_can_call(code=status.HTTP_400_BAD_REQUEST,) from e+ if config.classifier_type == "jev" and user_api_key_dict.budget_throttle_pct is not None:+ raise ProxyException(+ message="Budget has been exceeded! JEV Test Routing requires available budget.",+ type=ProxyErrorTypes.budget_exceeded,+ param=None,+ code=status.HTTP_400_BAD_REQUEST,+ )+@router.post("/auto_router/validate_complexity_router_config",diff --git a/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.pyindex a5c93c41a84..eb9076a9d2d 100644--- a/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_auto_router_endpoints.py@@ -12,6 +12,7 @@ import pytestfrom fastapi import HTTPException, Requestfrom pydantic import ValidationError+import litellmfrom litellm.proxy import proxy_serverfrom litellm.proxy._types import (LitellmUserRoles,@@ -488,6 +489,54 @@ async def test_jev_test_routing_enforces_key_budget_before_provider_invocation(client.evaluate.assert_awaited_once()+ "max_budget, spend, denied",+ ((0.0, 0.0, True), (1.0, 2.0, True), (1.0, 0.5, False), (None, 2.0, False)),+)+async def test_jev_test_routing_hard_blocks_exhausted_throttle_enabled_keys(+ monkeypatch: pytest.MonkeyPatch, max_budget: float | None, spend: float, denied: bool+) -> None:+ client: Final = AsyncMock(spec=JevClassifierClient)+ client.evaluate.return_value = JevSystemOneResponse(+ model="jev-test",+ answers={+ "tier": JevChoiceAnswer(type="choice", choice="SIMPLE", probabilities={"SIMPLE": 1.0}, confidence=1.0)+ },+ )+ monkeypatch.setattr(litellm, "budget_exceeded_throttle_percentage", 0.1)+ monkeypatch.setattr(proxy_server, "llm_router", _router())+ monkeypatch.setattr(auto_router_endpoints, "ComplexityRouter", partial(ComplexityRouter, jev_client=client))+ actor: Final = UserAPIKeyAuth(+ user_role=LitellmUserRoles.PROXY_ADMIN,+ api_key="sk-jev-throttle-test",+ user_id="admin",+ models=["cheap-model", "typesafe/jev-test"],+ max_budget=max_budget,+ spend=spend,+ rpm_limit=100,+ metadata={"throttle_on_budget_exceeded": True},+ )+ request: Final = _request(+ "what is 2+2",+ classifier_type="jev",+ jev_classifier_config={"model": "jev-test"},+ )+ if denied:+ with pytest.raises(ProxyException) as exc_info:+ await preview_auto_router_routing(http_request=ROUTING_HTTP_REQUEST, data=request, user_api_key_dict=actor)+ assert exc_info.value.type == ProxyErrorTypes.budget_exceeded+ assert exc_info.value.code == "400"+ client.evaluate.assert_not_called()+ return++ response: Final = await preview_auto_router_routing(+ http_request=ROUTING_HTTP_REQUEST, data=request, user_api_key_dict=actor+ )+ assert response.routing_decision["cause"] == "jev_classifier"+ client.evaluate.assert_awaited_once()++@pytest.mark.parametrize("max_budget, spend", ((0.0, 0.0), (1.0, 2.0)))@pytest.mark.asyncioasync def test_a_heuristic_config_does_not_need_a_budget(