mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(proxy): check precedence when a team edit makes an unenforced model_max_budget entry take effect
This commit is contained in:
parent
67f921404b
commit
7a0693e91f
3 changed files with 24 additions and 1 deletions
|
|
@ -743,6 +743,10 @@ def _window_reset_at(started_at: float | None, budget_duration: str | None, now:
|
|||
return datetime.fromtimestamp(ends_at, tz=timezone.utc).isoformat()
|
||||
|
||||
|
||||
def is_enforced_budget_entry(raw_budget_config: object) -> bool:
|
||||
return _usable_budget_config(raw_budget_config) is not None
|
||||
|
||||
|
||||
def _usable_budget_config(raw_budget_config: object) -> BudgetConfig | None:
|
||||
try:
|
||||
budget_config: Final = BudgetConfig.model_validate(raw_budget_config)
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ from litellm.proxy.hooks.model_max_budget_limiter import (
|
|||
build_model_max_budget_usage,
|
||||
entries_outranked_by,
|
||||
entry_names_model,
|
||||
is_enforced_budget_entry,
|
||||
proxy_routed_models,
|
||||
resolve_model_budget,
|
||||
)
|
||||
|
|
@ -1499,7 +1500,8 @@ def _check_team_model_budget_update_authority(
|
|||
existing = _existing_model_cap(existing_model_max_budget.get(entry))
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -17746,6 +17746,10 @@ def test_team_admin_cannot_add_an_entry_that_takes_precedence_over_a_cap(
|
|||
{**_TEAM_OPUS_FAMILY_CAP, "opus-group": {"rpm_limit": 10}},
|
||||
{**_TEAM_OPUS_FAMILY_CAP, "opus-group": {"rpm_limit": 20}},
|
||||
),
|
||||
(
|
||||
{**_TEAM_OPUS_FAMILY_CAP, "claude-opus-4-8": {"rpm_limit": 10, "budget_duration": "1d"}},
|
||||
{**_TEAM_OPUS_FAMILY_CAP, "claude-opus-4-8": {"max_budget": 1000.0, "budget_duration": "1d"}},
|
||||
),
|
||||
(
|
||||
_TEAM_OPUS_FAMILY_CAP,
|
||||
{**_TEAM_OPUS_FAMILY_CAP, "gemini-3-pro*": {"max_budget": 1000.0, "budget_duration": "1d"}},
|
||||
|
|
@ -17761,6 +17765,7 @@ def test_team_admin_cannot_add_an_entry_that_takes_precedence_over_a_cap(
|
|||
"unchanged_looser_entry",
|
||||
"tightened_looser_entry",
|
||||
"uncapped_entry_edited",
|
||||
"enforced_uncapped_entry_capped",
|
||||
"pattern_sharing_only_a_wildcard_route",
|
||||
],
|
||||
)
|
||||
|
|
@ -17770,6 +17775,18 @@ def test_team_admin_can_keep_or_tighten_entries_and_add_ones_that_outrank_no_cap
|
|||
assert _check_team_admin_model_caps(existing=existing, requested=requested) is None
|
||||
|
||||
|
||||
def test_team_admin_cannot_make_an_unenforced_entry_take_precedence_over_a_cap() -> None:
|
||||
existing: Final = {**_TEAM_OPUS_FAMILY_CAP, "claude-opus-4-8": {"rpm_limit": 10}}
|
||||
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
_check_team_admin_model_caps(
|
||||
existing=existing,
|
||||
requested={**existing, "claude-opus-4-8": {"max_budget": 1000.0, "budget_duration": "1d"}},
|
||||
)
|
||||
assert exc.value.status_code == 403
|
||||
assert "'claude-opus*'" 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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue