From 67f921404bbcb8b85b25c96cb732c4fc0a230c92 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 08:45:56 -0700 Subject: [PATCH] fix(proxy): name the entry holding the cap in the team model budget raise refusal --- .../management_endpoints/team_endpoints.py | 12 ++++++----- .../test_team_endpoints.py | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index 6948f620b73..2f5f39533d5 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -1498,11 +1498,13 @@ def _check_team_model_budget_update_authority( for entry, proposed in requested.items(): existing = _existing_model_cap(existing_model_max_budget.get(entry)) if existing is not None: - _check_existing_model_cap_kept(entry=entry, proposed=proposed, existing=existing) + _check_existing_model_cap_kept(entry=entry, cap_entry=entry, proposed=proposed, existing=existing) 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(entry=entry, proposed=proposed, existing=governing.budget_config) + _check_existing_model_cap_kept( + entry=entry, cap_entry=governing.budget_model, proposed=proposed, existing=governing.budget_config + ) _check_new_entry_outranks_no_cap( entry=entry, existing_model_max_budget=existing_model_max_budget, @@ -1511,7 +1513,7 @@ def _check_team_model_budget_update_authority( ) -def _check_existing_model_cap_kept(entry: str, proposed: BudgetConfig, existing: BudgetConfig) -> None: +def _check_existing_model_cap_kept(entry: str, cap_entry: str, proposed: BudgetConfig, existing: BudgetConfig) -> None: if existing.max_budget is None or not _looser_model_cap(proposed=proposed, cap=existing): return raise HTTPException( @@ -1519,8 +1521,8 @@ def _check_existing_model_cap_kept(entry: str, proposed: BudgetConfig, existing: detail={ "error": ( f"Only a proxy admin can raise a team's model_max_budget for {entry!r} or change its " - f"budget_duration. Current max_budget={existing.max_budget} per {existing.budget_duration}, " - f"requested={proposed.max_budget} per {proposed.budget_duration}." + f"budget_duration. Current max_budget={existing.max_budget} per {existing.budget_duration} " + f"(entry {cap_entry!r}), requested={proposed.max_budget} per {proposed.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 5f8005fa76a..5fdbbff01a9 100644 --- a/tests/unit/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_team_endpoints.py @@ -17571,6 +17571,26 @@ def test_team_admin_cannot_loosen_team_model_caps(requested) -> None: assert "proxy admin" in exc.value.detail["error"] +def test_team_cap_refusal_names_the_entry_holding_the_cap() -> None: + from litellm.proxy.management_endpoints.team_endpoints import _check_team_model_budget_update_authority + + with pytest.raises(HTTPException) as exc: + _check_team_model_budget_update_authority( + data=UpdateTeamRequest( + team_id="t1", + model_max_budget={ + **_EXISTING_TEAM_MODEL_CAPS, + "openai/gpt-4o": {"max_budget": 1000.0, "budget_duration": "1d"}, + }, + ), + user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.INTERNAL_USER, user_id="team-admin"), + existing_model_max_budget=_EXISTING_TEAM_MODEL_CAPS, + ) + assert exc.value.status_code == 403 + assert "for 'openai/gpt-4o'" in exc.value.detail["error"] + assert "(entry 'gpt-4o')" in exc.value.detail["error"] + + @pytest.mark.parametrize( "requested", [