diff --git a/litellm/proxy/common_utils/reset_budget_job.py b/litellm/proxy/common_utils/reset_budget_job.py index 71ded646540..4909f040729 100644 --- a/litellm/proxy/common_utils/reset_budget_job.py +++ b/litellm/proxy/common_utils/reset_budget_job.py @@ -143,7 +143,7 @@ class _ResetBand: def _reset_band(max_budget: float | None, rollover_max_budget: float | None) -> _ResetBand | None: - if max_budget is None or not math.isfinite(max_budget): + if max_budget is None or not math.isfinite(max_budget) or max_budget < 0: return None keep_overage: Final = litellm.budget_rollover is True lo: Final = ( diff --git a/tests/test_litellm/proxy/common_utils/test_reset_budget_job.py b/tests/test_litellm/proxy/common_utils/test_reset_budget_job.py index 8f5e2a114c8..429711470c4 100644 --- a/tests/test_litellm/proxy/common_utils/test_reset_budget_job.py +++ b/tests/test_litellm/proxy/common_utils/test_reset_budget_job.py @@ -3696,6 +3696,14 @@ def test_reset_band_zero_max_budget_keeps_overage_without_credit(rollover_enable assert _reset_spend(0.0, band) == 0.0 +def test_reset_band_negative_max_budget_never_opens_a_band(rollover_enabled): + """A negative max_budget is not an allowance, so budget_rollover on must not + turn each reset into spend - (-budget) and ratchet the balance upward.""" + assert _reset_band(-50.0, None) is None + assert _reset_band(-50.0, 600.0) is None + assert _reset_spend(30.0, _reset_band(-50.0, 600.0)) == 0.0 + + def test_direct_reset_carries_unused_allowance_as_negative_spend( reset_budget_job, mock_prisma_client, monkeypatch ):