From d150c818ca4e16f95d5996e32824be6ff5b8ba5d Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 13:37:08 -0700 Subject: [PATCH] fix(proxy): keep a legacy model_max_budget row's stored cap when an org admin gives it a budget_duration --- litellm/proxy/management_endpoints/team_endpoints.py | 7 ++++--- .../proxy/management_endpoints/test_team_endpoints.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index fc25146d8e0..a256f417dfa 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -1498,9 +1498,10 @@ def _check_team_model_budget_update_authority( routed_models: Final = routed_models_source(data.team_id) for entry, proposed in requested.items(): existing = _existing_model_cap(existing_model_max_budget.get(entry)) - if existing is not None and (is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed)): + if existing is not None: _check_existing_model_cap_kept(entry=entry, cap_entry=entry, proposed=proposed, existing=existing) - continue + if is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed): + continue governing = resolve_model_budget(model=entry, model_max_budget=existing_model_max_budget, team_id=data.team_id) if governing is not None and entry_names_model(entry=governing.budget_model, model=entry): _check_existing_model_cap_kept( @@ -1583,7 +1584,7 @@ def _looser_model_cap(proposed: BudgetConfig, cap: BudgetConfig) -> bool: return ( proposed.max_budget is None or (cap.max_budget is not None and proposed.max_budget > cap.max_budget) - or proposed.budget_duration != cap.budget_duration + or (is_enforced_budget_entry(cap) and proposed.budget_duration != cap.budget_duration) ) diff --git a/tests/unit/proxy/management_endpoints/test_team_endpoints.py b/tests/unit/proxy/management_endpoints/test_team_endpoints.py index 2c608c34da7..e51f26bf1c3 100644 --- a/tests/unit/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_team_endpoints.py @@ -17797,6 +17797,16 @@ def test_team_admin_cannot_make_an_unenforced_entry_take_precedence_over_a_cap() assert "'claude-opus*'" in exc.value.detail["error"] +def test_team_admin_cannot_raise_an_unenforced_cap_while_enforcing_it() -> None: + with pytest.raises(HTTPException) as exc: + _check_team_admin_model_caps( + existing={"gpt-4o": {"max_budget": 10.0}}, + requested={"gpt-4o": {"max_budget": 20.0, "budget_duration": "1d"}}, + ) + assert exc.value.status_code == 403 + assert "(entry 'gpt-4o')" in exc.value.detail["error"] + + @pytest.mark.parametrize("added_entry", _BEDROCK_ROUTE_ADDED_ENTRIES, ids=["model", "pattern"]) def test_team_admin_cannot_lift_a_bedrock_vendor_cap_through_a_bedrock_wildcard_route(added_entry: str) -> None: with pytest.raises(HTTPException) as exc: