Skip to content

fix(router): treat a max_budget of zero as a hard stop - #1

Closed
abeed09 wants to merge 2 commits into
mainfrom
cursor/router-zero-budget-blocks-spend-e485
Closed

abeed09 wants to merge 2 commits into
mainfrom
cursor/router-zero-budget-blocks-spend-e485

Conversation

@abeed09

@abeed09 abeed09 commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

TLDR

Problem this solves:

  • A provider, deployment, or tag budget of $0 was ignored
  • Those routes kept taking traffic after the cap was set

How it solves it:

  • A configured cap is enforced, including a cap of 0
  • An empty provider cap no longer skips that deployment's other caps
  • The deployment over-budget line prints the dollar cap

Intentional product change: max_budget 0 now blocks spend on that provider, deployment, or tag. A provider budget entry with a time window and no dollar amount no longer removes its deployments

User Flow

Before: an admin who sets a provider budget of zero still sees that provider serve traffic

  1. They set the OpenAI budget to 0 dollars for 1 day
  2. A client requests a model on that provider, even after it has already spent money
  3. The request succeeds and that deployment stays in the rotation

After: the same budget rejects the request before it is sent

  1. They set the OpenAI budget to 0 dollars for 1 day
  2. A client requests a model on that provider, including when recorded spend is still zero
  3. The request fails with "No deployments available - crossed budget: Exceeded budget for provider openai: 0.0 >= 0.0"
  4. A sibling provider with no cap still serves, and a deployment or tag cap of 0 fails the same way

Relevant issues

Fixes BerriAI#43214

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Python router, mock_response set so an allowed call does not leave the process. A blocked call errors before any provider request, so there is no provider charge. This is the same in-process router path as the issue

Before (1a58162)

Provider already spent $50 against a $0 cap

  1. Filter OpenAI with max_budget=0, budget_duration=1d, and recorded spend 50.0
  2. Observed routable=True and debug=''

Router completion with provider max_budget 0 and no recorded spend

  1. Router.acompletion for openai/gpt-4 with mock_response set
  2. Observed served: served

Router completion with provider max_budget 0.01 and no recorded spend

  1. Same completion with max_budget=0.01
  2. Observed served: served

After (6214d5d)

Provider already spent $50 against a $0 cap

  1. Same filter as before
  2. Observed routable=False and debug='Exceeded budget for provider openai: 50.0 >= 0.0\n'

Router completion with provider max_budget 0 and no recorded spend

  1. Same Router.acompletion as before
  2. Observed ValueError: No deployments available - crossed budget: Exceeded budget for provider openai: 0.0 >= 0.0

Router completion with provider max_budget 0.01 and no recorded spend

  1. Same completion with max_budget=0.01
  2. Observed served: served

Deployment max_budget 0

  1. One deployment with litellm_params.max_budget=0 and budget_duration=1d, then the same completion
  2. Observed ValueError: No deployments available - crossed budget: Exceeded budget for deployment model_name: gpt-4, litellm_params.model: openai/gpt-4, model_id: dep-1: 0.0 >= 0.0

Mutation: putting the truthy if config.max_budget and spend >= cap check back fails 6 of the new cases: provider zero, deployment zero, tag zero, an unset provider cap, and the deployment message that used to print the time window

Type

Bug Fix

Caveats

Low

  • A provider entry with a time window and no dollar cap used to drop its deployments
  • Those deployments stay routable now, and a deployment or tag cap on them still applies

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Open in Web Open in Cursor 

cursoragent and others added 2 commits September 26, 2026 02:46
A provider, deployment, or tag cap of 0 was skipped because the
spend check used the dollar amount as a boolean. Compare against
None instead, and keep checking deployment and tag caps when a
provider entry has no dollar limit.

Co-authored-by: abeed09 <abeed09@users.noreply.github.com>
The provider, deployment, and tag checks share one parametrized
test, plus the case where an empty provider cap must still honor
a deployment cap.

Co-authored-by: abeed09 <abeed09@users.noreply.github.com>
@abeed09

abeed09 commented Sep 26, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream LiteLLM pull request at BerriAI#43277. This fork pull request was closed without merging.

@abeed09 abeed09 closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RouterBudgetLimiting treats max_budget=0 as unlimited instead of blocking all spend (provider/deployment/tag)

2 participants