fix(proxy): block project requests when max_budget is 0 - #41997
Conversation
A project max_budget of 0 was treated as unbudgeted by #41354, while key budgets block at 0 and null is the unlimited value. Drop the <= 0 skip so 0 blocks and null stays unlimited
|
| 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): |
There was a problem hiding this comment.
Unflagged compatibility change
Removing this exemption immediately blocks existing projects with zero budgets. This violates the repository directive to avoid backward-incompatible changes without user-controlled flags, so the requirement must be satisfied before merging
Rule Used: What: avoid backwards-incompatible changes without user-controlled flags Why: This breaks current behaviour for users using existing functionality Example of BAD: this PR (#22164) introduced run_post_custom... (source)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
max_budgetof 0 mean unlimitedHow it solves it:
<= 0skip in the project max budget checkUser Flow
Before: a proxy admin creates a project with a $0 budget to stop it from spending, and its keys keep working
"max_budget": 0and gets back aproject_idproject_idand get back a keyAfter: the same project blocks on the first request, and sending null is how the admin lifts the limit
"max_budget": 0and gets back aproject_idproject_idand get back a keyBudget has been exceeded! Project=<project_id> Current cost: 0.0, Max budget: 0.0"max_budget": null, and the same key returns 200 againRelevant issues
Follow-up to #41354
Affected release
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Proxy started with
litellm --config litellm/proxy/dev_config.yaml --port 4173 --use_v2_migration_resolver, master keysk-1234, real OpenAI calls togpt-5.5. Shared shell helpers for both legs:Before (eda1fab)
A project with max_budget 0 blocks
setup 0; chat "$KEY"200 Hi!A project with max_budget null is unlimited
setup null; chat "$KEY"200 Hi!Sending max_budget null lifts a 0 budget
setup 0; curl -s $B/project/update "${ADMIN[@]}" -d "{\"project_id\":\"$PID\",\"max_budget\":null}"; chat "$KEY"max_budget: None, then200 Hi!After (162d622)
A project with max_budget 0 blocks
setup 0; chat "$KEY"429 Budget has been exceeded! Project=104764c1-c39e-4ae8-9b59-ab679777bf6e Current cost: 0.0, Max budget: 0.0A project with max_budget null is unlimited
setup null; chat "$KEY"200 Hi!Sending max_budget null lifts a 0 budget
setup 0; curl -s $B/project/update "${ADMIN[@]}" -d "{\"project_id\":\"$PID\",\"max_budget\":null}"; chat "$KEY"max_budget: None, then200 Hi!Type
Bug Fix
Caveats (if any)
Severe
max_budget: 0start returning 429"max_budget": nullLow
max_budgetstill treat 0 as unlimited, and this PR does not touch themFinal Attestation