diff --git a/litellm/proxy/common_utils/reset_budget_job.py b/litellm/proxy/common_utils/reset_budget_job.py index 73c0c29178a..71ded646540 100644 --- a/litellm/proxy/common_utils/reset_budget_job.py +++ b/litellm/proxy/common_utils/reset_budget_job.py @@ -143,12 +143,15 @@ 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) or max_budget <= 0: + if max_budget is None or not math.isfinite(max_budget): return None keep_overage: Final = litellm.budget_rollover is True lo: Final = ( max_budget - rollover_max_budget - if rollover_max_budget is not None and math.isfinite(rollover_max_budget) and rollover_max_budget > max_budget + if max_budget > 0 + and rollover_max_budget is not None + and math.isfinite(rollover_max_budget) + and rollover_max_budget > max_budget else 0.0 ) if lo == 0.0 and not keep_overage: 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 82759cc816d..8f5e2a114c8 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 @@ -3687,6 +3687,15 @@ def test_reset_spend_forgives_overage_when_rollover_off(): assert _reset_spend(30.0, band) == -70.0 +def test_reset_band_zero_max_budget_keeps_overage_without_credit(rollover_enabled): + """budget_rollover on with max_budget 0 still carries the whole overage, as it + did before caps existed, and a cap on a zero allowance never opens a credit floor.""" + band = _reset_band(0.0, 600.0) + assert band == _ResetBand(base=0.0, lo=0.0, keep_overage=True) + assert _reset_spend(40.0, band) == 40.0 + assert _reset_spend(0.0, band) == 0.0 + + def test_direct_reset_carries_unused_allowance_as_negative_spend( reset_budget_job, mock_prisma_client, monkeypatch ):