diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index af0608629f1..fc25146d8e0 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -1498,10 +1498,9 @@ 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: + if existing is not None and (is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed)): _check_existing_model_cap_kept(entry=entry, cap_entry=entry, proposed=proposed, existing=existing) - if is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed): - continue + 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( @@ -1575,7 +1574,9 @@ def _capped_entries_outranked_by( entries_outranked_by(entry=entry, model_max_budget=existing_model_max_budget, routed_models=routed_models), ) outranked_caps: Final = ((name, _existing_model_cap(existing_model_max_budget[name])) for name in outranked_names) - yield from ((name, cap) for name, cap in outranked_caps if cap is not None and cap.max_budget is not None) + yield from ( + (name, cap) for name, cap in outranked_caps if name != entry and cap is not None and cap.max_budget is not None + ) def _looser_model_cap(proposed: BudgetConfig, cap: BudgetConfig) -> bool: diff --git a/tests/unit/proxy/management_endpoints/test_team_endpoints.py b/tests/unit/proxy/management_endpoints/test_team_endpoints.py index d4465bef7a6..2c608c34da7 100644 --- a/tests/unit/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_team_endpoints.py @@ -17754,6 +17754,14 @@ def test_team_admin_cannot_add_an_entry_that_takes_precedence_over_a_cap( _TEAM_OPUS_FAMILY_CAP, {**_TEAM_OPUS_FAMILY_CAP, "gemini-3-pro*": {"max_budget": 1000.0, "budget_duration": "1d"}}, ), + ( + {**_TEAM_OPUS_FAMILY_CAP, "gpt-4o": {"max_budget": 10.0}}, + {**_TEAM_OPUS_FAMILY_CAP, "gpt-4o": {"max_budget": 10.0, "budget_duration": "1d"}}, + ), + ( + {"z-anthropic-group": {"max_budget": 10.0}}, + {"z-anthropic-group": {"max_budget": 10.0, "budget_duration": "1d"}}, + ), ], ids=[ "less_specific_pattern", @@ -17767,6 +17775,8 @@ def test_team_admin_cannot_add_an_entry_that_takes_precedence_over_a_cap( "uncapped_entry_edited", "enforced_uncapped_entry_capped", "pattern_sharing_only_a_wildcard_route", + "unenforced_capped_model_given_a_duration", + "unenforced_capped_wildcard_group_given_a_duration", ], ) def test_team_admin_can_keep_or_tighten_entries_and_add_ones_that_outrank_no_cap(