Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

merge: resolve conflict with main, move temp budget patch fields to shared member_budget_patch

Devin AI9d5f65c26c54
diff --cc litellm/proxy/management_endpoints/common_utils.py
index 546078cce09,c498c186253..6f88b05a8ae
--- a/litellm/proxy/management_endpoints/common_utils.py
+++ b/litellm/proxy/management_endpoints/common_utils.py
@@@ -492,6 -479,33 +481,35 @@@ _TEAM_MEMBER_BUDGET_LIMIT_FIELDS: Fina
)
+ MEMBER_BUDGET_PATCH_FIELDS: Final = MappingProxyType(
+ {
+ "max_budget_in_team": "max_budget",
+ "tpm_limit": "tpm_limit",
+ "rpm_limit": "rpm_limit",
+ "budget_duration": "budget_duration",
+ "allowed_models": "allowed_models",
++ "temp_budget_increase": "temp_budget_increase",
++ "temp_budget_expiry": "temp_budget_expiry",
+ }
+ )
+
+
+ def _prisma_value(value: object) -> object:
+ return list(value) if isinstance(value, tuple) else value
+
+
+ def member_budget_patch(source: BaseModel) -> dict[str, Any]:
+ """Map the per-member limit fields a request actually set to their budget-table
+ columns (merge-patch: a sent value updates, an explicit null clears, an absent
+ field is left untouched)."""
+ provided: Final = source.model_dump(exclude_unset=True)
+ return {
+ column: _prisma_value(provided[request_field])
+ for request_field, column in MEMBER_BUDGET_PATCH_FIELDS.items()
+ if request_field in provided
+ }
+
+
def _is_set_budget_value(value: object) -> bool:
if value is None:
return False
diff --cc tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
index a7748220e44,a89bc9a8a3e..4b3adcfff4e
--- a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
+++ b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
@@@ -15422,37 -15422,3 +15422,37 @@@ async def test_team_info_reports_what_t
)
assert response["team_info"].caller_edit_access.model_dump(mode="json") == expected
+
+
- def test_build_member_budget_patch_maps_temp_budget_fields() -> None:
- from litellm.proxy.management_endpoints.team_endpoints import _build_member_budget_patch
++def test_member_budget_patch_maps_temp_budget_fields() -> None:
++ from litellm.proxy.management_endpoints.common_utils import member_budget_patch
+
+ expiry: Final = datetime(2030, 1, 1, tzinfo=timezone.utc)
+ request: Final = TeamMemberUpdateRequest(
+ team_id="team-1",
+ user_id="user-1",
+ temp_budget_increase=50.0,
+ temp_budget_expiry=expiry,
+ )
- assert _build_member_budget_patch(request) == {
++ assert member_budget_patch(request) == {
+ "temp_budget_increase": 50.0,
+ "temp_budget_expiry": expiry,
+ }
+
+
+def test_team_member_update_request_temp_budget_fields_must_be_set_together() -> None:
+ with pytest.raises(ValidationError, match="temp_budget_increase and temp_budget_expiry must be set together"):
+ TeamMemberUpdateRequest(team_id="team-1", user_id="user-1", temp_budget_increase=50.0)
+ with pytest.raises(ValidationError, match="temp_budget_increase and temp_budget_expiry must be set together"):
+ TeamMemberUpdateRequest(team_id="team-1", user_id="user-1", temp_budget_expiry="2030-01-01T00:00:00Z")
+
+
+ ("increase", "message"),
+ [(-1.0, "greater than or equal to 0"), (float("inf"), "finite number")],
+)
+def test_team_member_update_request_rejects_unusable_temp_budget_increase(increase: float, message: str) -> None:
+ with pytest.raises(ValidationError, match=message):
+ TeamMemberUpdateRequest(
+ team_id="team-1", user_id="user-1", temp_budget_increase=increase, temp_budget_expiry="2030-01-01T00:00:00Z"
+ )