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): block project requests when max_budget is 0
ryan-crabbe-berri162d6225e065
diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex 61d2fa572a1..fbcb35d66c9 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -5680,7 +5680,7 @@ async def _project_max_budget_check(if project_object.litellm_budget_table is not None:max_budget = project_object.litellm_budget_table.max_budget- if max_budget is None or max_budget <= 0 or not math.isfinite(max_budget):+ if max_budget is None or not math.isfinite(max_budget):returnfrom litellm.proxy.proxy_server import get_current_spenddiff --git a/tests/test_litellm/proxy/auth/test_auth_checks.py b/tests/test_litellm/proxy/auth/test_auth_checks.pyindex 1ae986db23b..0a6f6d8e69b 100644--- a/tests/test_litellm/proxy/auth/test_auth_checks.py+++ b/tests/test_litellm/proxy/auth/test_auth_checks.py@@ -7572,7 +7572,7 @@ async def test_project_allowlist_enforced_when_key_models_empty():assert exc_info.value.code == "403"-def _project_with_budget(spend: float, max_budget: float):+def _project_with_budget(spend: float, max_budget: float | None):from litellm.proxy._types import LiteLLM_BudgetTable, LiteLLM_ProjectTableCachedObjreturn LiteLLM_ProjectTableCachedObj(@@ -7592,11 +7592,12 @@ def _project_with_budget(spend: float, max_budget: float):pytest.param(4.99, 0.0, 5.0, False, id="counter-under-budget-admits"),pytest.param(None, 5.0, 5.0, True, id="no-counter-falls-back-to-persisted-spend"),pytest.param(None, 0.0, 5.0, False, id="no-counter-and-no-persisted-spend-admits"),- pytest.param(12.5, 12.5, 0.0, False, id="zero-budget-is-unbudgeted"),- pytest.param(12.5, 12.5, -1.0, False, id="negative-budget-is-unbudgeted"),+ pytest.param(None, 0.0, 0.0, True, id="zero-budget-blocks-before-any-spend"),+ pytest.param(12.5, 12.5, 0.0, True, id="zero-budget-blocks-with-spend"),+ pytest.param(12.5, 12.5, None, False, id="null-budget-is-unlimited"),],)-async def test_project_max_budget_check_blocks_only_when_live_spend_reaches_a_positive_budget(+async def test_project_max_budget_check_blocks_when_live_spend_reaches_the_budget(counter_spend, db_spend, max_budget, blocks):from litellm.caching.dual_cache import DualCache@@ -7631,7 +7632,7 @@ async def test_project_max_budget_check_blocks_only_when_live_spend_reaches_a_poassert exc_info.value.entity_type == Litellm_EntityType.PROJECT.valueassert exc_info.value.entity_id == "p-budget"- assert exc_info.value.current_cost == 5.0+ assert exc_info.value.current_cost == (db_spend if counter_spend is None else counter_spend)proxy_logging_obj.budget_alerts.assert_awaited_once()assert proxy_logging_obj.budget_alerts.await_args.kwargs["type"] == "project_budget"