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]

feat(proxy): let proxy admins open soft_budget to team admins (#46485)

yuneng-jiang1d9dd7b06701
diff --git a/litellm/proxy/management_endpoints/team_admin_field_permissions.py b/litellm/proxy/management_endpoints/team_admin_field_permissions.py
index 54e303f69b9..67cbb0be45d 100644
--- a/litellm/proxy/management_endpoints/team_admin_field_permissions.py
+++ b/litellm/proxy/management_endpoints/team_admin_field_permissions.py
@@ -31,7 +31,9 @@ from litellm.proxy._types import (
TEAM_ADMIN_EDITABLE_TEAM_FIELDS_SETTING: Final = "team_admin_editable_team_fields"
# TODO(LIT-5722): add the remaining team settings one per PR, each with its value-diff tests and dashboard field
-SUPPORTED_TEAM_ADMIN_EDITABLE_TEAM_FIELDS: Final[frozenset[str]] = frozenset({"tpm_limit", "rpm_limit", "max_budget"})
+SUPPORTED_TEAM_ADMIN_EDITABLE_TEAM_FIELDS: Final[frozenset[str]] = frozenset(
+ {"tpm_limit", "rpm_limit", "max_budget", "soft_budget"}
+)
TEAM_ADMIN_RAISE_MAX_BUDGET_PERMISSION: Final = "raise_max_budget"
TEAM_ADMIN_PROJECTS_PERMISSION: Final = "projects"
TEAM_ADMIN_MEMBER_KEY_BUDGETS_PERMISSION: Final = "member_key_budgets"
diff --git a/tests/integration/management/test_team_update.py b/tests/integration/management/test_team_update.py
index b7b5fe34c87..0414d0bb77f 100644
--- a/tests/integration/management/test_team_update.py
+++ b/tests/integration/management/test_team_update.py
@@ -4,6 +4,7 @@ from litellm.proxy._types import LitellmUserRoles
from tests.integration._support.actors import Actor, SeededKey
from tests.integration._support.actors import create_scratch_actor, create_scratch_team
+from tests.integration._support.client import team_admin_permissions
pytestmark = pytest.mark.asyncio(loop_scope="session")
@@ -161,6 +162,43 @@ async def test_team_update_org_admin_resolved_from_team_without_org_context(
assert "Team admin editable fields" in denied_team_admin.text, denied_team_admin.text
+async def test_team_update_team_admin_soft_budget_follows_the_proxy_admin_grant(gateway_client, db, resources, actors):
+ callers = await _callers(db, actors, resources.prefix)
+ await _seed_target(db, actors, callers, "alpha", resources.prefix)
+ headers = {"Authorization": f"Bearer {callers[Actor.TEAM_ADMIN].cleartext}"}
+ body = {"team_id": resources.prefix, "soft_budget": 7.5}
+
+ with team_admin_permissions(gateway_client.gateway, ["max_budget"]):
+ denied = await gateway_client.post("/team/update", headers=headers, json=body)
+ assert denied.status_code == 403, denied.text
+ assert "'soft_budget'" in denied.text and "Team admin editable fields" in denied.text, denied.text
+ row = await db.db.litellm_teamtable.find_unique(where={"team_id": resources.prefix})
+ assert row is not None and row.soft_budget != 7.5, "denied but team mutated"
+
+ with team_admin_permissions(gateway_client.gateway, ["soft_budget"]):
+ allowed = await gateway_client.post("/team/update", headers=headers, json=body)
+ assert allowed.status_code == 200, allowed.text
+ row = await db.db.litellm_teamtable.find_unique(where={"team_id": resources.prefix})
+ assert row is not None and row.soft_budget == 7.5
+
+
+async def test_team_update_team_admin_cannot_set_soft_budget_on_a_team_they_do_not_administer(
+ gateway_client, db, resources, actors
+):
+ callers = await _callers(db, actors, resources.prefix)
+ await _seed_target(db, actors, callers, "beta", resources.prefix)
+
+ with team_admin_permissions(gateway_client.gateway, ["soft_budget"]):
+ resp = await gateway_client.post(
+ "/team/update",
+ headers={"Authorization": f"Bearer {callers[Actor.TEAM_ADMIN].cleartext}"},
+ json={"team_id": resources.prefix, "soft_budget": 7.5},
+ )
+ assert resp.status_code == 403, resp.text
+ row = await db.db.litellm_teamtable.find_unique(where={"team_id": resources.prefix})
+ assert row is not None and row.soft_budget != 7.5, "denied but team mutated"
+
+
# Relocation gate — moving a team to a different org. The resources team starts
# in actors.org_a_id; each scenario relocates it to actors.org_b_id. PROXY_ADMIN bypasses;
# ORG_B_ADMIN reaches the handler but holds no role on the source team (403);
diff --git a/tests/unit/proxy/management_endpoints/test_team_admin_field_permissions.py b/tests/unit/proxy/management_endpoints/test_team_admin_field_permissions.py
index 730f4640da8..0c9ed9356f8 100644
--- a/tests/unit/proxy/management_endpoints/test_team_admin_field_permissions.py
+++ b/tests/unit/proxy/management_endpoints/test_team_admin_field_permissions.py
@@ -13,6 +13,7 @@ from litellm.proxy._types import (
UpdateTeamRequest,
)
from litellm.proxy.management_endpoints.team_admin_field_permissions import (
+ SUPPORTED_TEAM_ADMIN_EDITABLE_TEAM_FIELDS,
TeamAdminEditAllowed,
TeamAdminEditingDisabled,
TeamAdminFieldNotPermitted,
@@ -191,6 +192,31 @@ class TestTeamAdminEditVerdict:
assert verdict == TeamAdminFieldNotPermitted(field="blocked")
+def _enabled(*fields: str) -> frozenset[str]:
+ return resolve_team_admin_editable_fields(
+ {"team_admin_editable_team_fields": list(fields)}, SUPPORTED_TEAM_ADMIN_EDITABLE_TEAM_FIELDS
+ )
+
+
+class TestSoftBudgetEdits:
+ def test_enabled_soft_budget_change_is_allowed(self):
+ data: Final = UpdateTeamRequest(team_id="team-1", soft_budget=20.0)
+ verdict: Final = team_admin_edit_verdict(data, _team(soft_budget=10.0), _enabled("soft_budget"))
+ assert isinstance(verdict, TeamAdminEditAllowed)
+ assert verdict.request.model_dump(exclude_unset=True) == {"team_id": "team-1", "soft_budget": 20.0}
+
+ def test_soft_budget_change_without_it_enabled_names_it(self):
+ data: Final = UpdateTeamRequest(team_id="team-1", soft_budget=20.0)
+ verdict: Final = team_admin_edit_verdict(data, _team(soft_budget=10.0), _enabled("max_budget"))
+ assert verdict == TeamAdminFieldNotPermitted(field="soft_budget")
+
+ def test_unchanged_soft_budget_resend_is_dropped_when_not_enabled(self):
+ data: Final = UpdateTeamRequest(team_id="team-1", tpm_limit=6, soft_budget=10)
+ verdict: Final = team_admin_edit_verdict(data, _team(soft_budget=10.0), _enabled("tpm_limit"))
+ assert isinstance(verdict, TeamAdminEditAllowed)
+ assert verdict.request.model_dump(exclude_unset=True) == {"team_id": "team-1", "tpm_limit": 6}
+
+
class TestTeamAdminRequestOrRaise:
def test_allowed_hands_back_its_request(self):
request = UpdateTeamRequest(team_id="team-1", tpm_limit=6)
diff --git a/ui/litellm-dashboard/src/components/Settings/AdminSettings/UISettings/TeamAdminEditableFieldsSettings.test.tsx b/ui/litellm-dashboard/src/components/Settings/AdminSettings/UISettings/TeamAdminEditableFieldsSettings.test.tsx
index ca90a4ac19d..36fbe086df3 100644
--- a/ui/litellm-dashboard/src/components/Settings/AdminSettings/UISettings/TeamAdminEditableFieldsSettings.test.tsx
+++ b/ui/litellm-dashboard/src/components/Settings/AdminSettings/UISettings/TeamAdminEditableFieldsSettings.test.tsx
@@ -127,6 +127,18 @@ describe("TeamAdminEditableFieldsSettings", () => {
expect(mutate).toHaveBeenCalledWith({ team_admin_editable_team_fields: ["max_budget"] }, expect.anything());
});
+ it("offers the soft budget as a named checkbox and saves it when ticked", async () => {
+ mockSettings(["max_budget", "soft_budget"], []);
+ const mutate = mockSave({});
+
+ renderWithProviders(<TeamAdminEditableFieldsSettings />);
+ fireEvent.click(screen.getByRole("checkbox", { name: "Soft Budget (USD)" }));
+ fireEvent.click(saveButton());
+
+ await waitFor(() => expect(mutate).toHaveBeenCalledTimes(1));
+ expect(mutate).toHaveBeenCalledWith({ team_admin_editable_team_fields: ["soft_budget"] }, expect.anything());
+ });
+
it("disables Save again when the draft is ticked back to the saved list", () => {
mockSettings(["tpm_limit"], []);
mockSave({});
diff --git a/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.test.tsx b/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.test.tsx
index 910760a8ee8..7fe6461e285 100644
--- a/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.test.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.test.tsx
@@ -13,7 +13,7 @@ const renderForm = (
const onCancel = vi.fn();
renderWithProviders(
<TeamAdminSettingsForm
- initialValues={{ tpm_limit: 1000, rpm_limit: 50, max_budget: 20 }}
+ initialValues={{ tpm_limit: 1000, rpm_limit: 50, max_budget: 20, soft_budget: 15 }}
editableFields={editableFields}
mayRaiseMaxBudget={overrides.mayRaiseMaxBudget ?? false}
isSaving={overrides.isSaving ?? false}
@@ -84,6 +84,22 @@ describe("TeamAdminSettingsForm", () => {
expect(save).toBeDisabled();
});
+ it("shows the soft budget when the proxy lets team admins edit it", () => {
+ renderForm(new Set(["soft_budget"]));
+
+ expect(screen.getByLabelText("Soft Budget (USD)")).toHaveValue(15);
+ });
+
+ it("saves a lowered soft budget and nothing else", async () => {
+ const user = userEvent.setup();
+ const { onSave } = renderForm(new Set(["soft_budget", "max_budget"]));
+
+ fireEvent.change(screen.getByLabelText("Soft Budget (USD)"), { target: { value: "10.5" } });
+ await user.click(screen.getByRole("button", { name: /save changes/i }));
+
+ await waitFor(() => expect(onSave).toHaveBeenCalledWith({ soft_budget: 10.5 }));
+ });
+
it("closes without saving on cancel", async () => {
const user = userEvent.setup();
const { onSave, onCancel } = renderForm(new Set(["tpm_limit"]));
diff --git a/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.tsx b/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.tsx
index ca80a21f65a..5ce50bb6c72 100644
--- a/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamAdminSettingsForm.tsx
@@ -22,13 +22,21 @@ import {
const numericInputSchema = z.union([z.string(), z.number()]).nullish();
-const teamAdminSettingsSchema = z.object({
+const teamAdminSettingsShape = {
tpm_limit: numericInputSchema,
rpm_limit: numericInputSchema,
max_budget: numericInputSchema,
-});
+ soft_budget: numericInputSchema,
+};
+
+const teamAdminSettingsSchema = z.object(teamAdminSettingsShape);
-const INPUT_STEP: Readonly<Record<TeamAdminSettingsField, number>> = { tpm_limit: 1, rpm_limit: 1, max_budget: 0.01 };
+const INPUT_STEP: Readonly<Record<TeamAdminSettingsField, number>> = {
+ tpm_limit: 1,
+ rpm_limit: 1,
+ max_budget: 0.01,
+ soft_budget: 0.01,
+};
const MAX_BUDGET_KEEP_OR_LOWER_HINT = "You can keep or lower this budget. Ask a proxy admin to raise it.";
const MAX_BUDGET_RAISE_HINT =
diff --git a/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx b/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
index 03cee6e5fc1..31d3016d4be 100644
--- a/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
@@ -2025,13 +2025,14 @@ describe("TeamInfoView", () => {
expect(toast.error).not.toHaveBeenCalled();
});
- it("prefills the RPM limit and budget a team admin may edit with the team's stored values", async () => {
+ it("prefills the RPM limit and budgets a team admin may edit with the team's stored values", async () => {
const user = userEvent.setup({ delay: null });
vi.mocked(networking.teamInfoCall).mockResolvedValue(
createMockTeamData({
rpm_limit: 50,
max_budget: 20,
- caller_edit_access: { kind: "team_admin", editable_fields: ["rpm_limit", "max_budget"] },
+ soft_budget: 15,
+ caller_edit_access: { kind: "team_admin", editable_fields: ["rpm_limit", "max_budget", "soft_budget"] },
}),
);
@@ -2042,6 +2043,7 @@ describe("TeamInfoView", () => {
expect(await screen.findByLabelText("Requests per minute Limit (RPM)")).toHaveValue(50);
expect(screen.getByLabelText("Max Budget (USD)")).toHaveValue(20);
+ expect(screen.getByLabelText("Soft Budget (USD)")).toHaveValue(15);
expect(screen.getByRole("button", { name: /save changes/i })).toBeDisabled();
});
diff --git a/ui/litellm-dashboard/src/components/team/TeamInfo.tsx b/ui/litellm-dashboard/src/components/team/TeamInfo.tsx
index 7663ef8c588..cfac81cb64b 100644
--- a/ui/litellm-dashboard/src/components/team/TeamInfo.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamInfo.tsx
@@ -1306,7 +1306,12 @@ const TeamInfoView: React.FC<TeamInfoProps> = ({
const teamAdminSettingsEditor =
teamEditAccess.kind === "team_admin" ? (
<TeamAdminSettingsForm
- initialValues={{ tpm_limit: info.tpm_limit, rpm_limit: info.rpm_limit, max_budget: info.max_budget }}
+ initialValues={{
+ tpm_limit: info.tpm_limit,
+ rpm_limit: info.rpm_limit,
+ max_budget: info.max_budget,
+ soft_budget: info.soft_budget,
+ }}
editableFields={teamEditAccess.editableFields}
mayRaiseMaxBudget={teamEditAccess.mayRaiseMaxBudget}
isSaving={isTeamSaving}
diff --git a/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.test.ts b/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.test.ts
index dc88f51293b..590dd806d7f 100644
--- a/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.test.ts
+++ b/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.test.ts
@@ -13,6 +13,7 @@ describe("teamAdminFieldLabel", () => {
["tpm_limit", "Tokens per minute Limit (TPM)"],
["rpm_limit", "Requests per minute Limit (RPM)"],
["max_budget", "Max Budget (USD)"],
+ ["soft_budget", "Soft Budget (USD)"],
["raise_max_budget", "Raise the team's max budget"],
["projects", "Create and update projects"],
["create_member_keys", "Create keys for team members"],
@@ -76,6 +77,27 @@ describe("teamAdminSettingsChanges", () => {
});
});
+describe("teamAdminSettingsChanges for the soft budget", () => {
+ const stored = { soft_budget: 50 };
+ const enabled = new Set(["soft_budget"]);
+
+ it("sends a changed soft budget as a number", () => {
+ expect(teamAdminSettingsChanges({ soft_budget: "40" }, stored, enabled)).toStrictEqual({ soft_budget: 40 });
+ });
+
+ it("sends a cleared soft budget as no soft budget", () => {
+ expect(teamAdminSettingsChanges({ soft_budget: "" }, stored, enabled)).toStrictEqual({ soft_budget: null });
+ });
+
+ it("leaves out an unchanged soft budget", () => {
+ expect(teamAdminSettingsChanges({ soft_budget: "50" }, stored, enabled)).toStrictEqual({});
+ });
+
+ it("leaves out a changed soft budget when the proxy did not enable it", () => {
+ expect(teamAdminSettingsChanges({ soft_budget: "40" }, stored, new Set(["max_budget"]))).toStrictEqual({});
+ });
+});
+
describe("parseTeamAdminEditableFields", () => {
it("returns the configured list", () => {
expect(parseTeamAdminEditableFields({ team_admin_editable_team_fields: ["tpm_limit", "rpm_limit"] })).toEqual([
diff --git a/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.ts b/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.ts
index 1fed045292b..3ab51b4cdbb 100644
--- a/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.ts
+++ b/ui/litellm-dashboard/src/components/team/teamAdminEditAccess.ts
@@ -48,7 +48,7 @@ export const parseSupportedTeamAdminEditableFields = (uiSettingsFieldSchema: unk
return items.success ? fieldListSchema.parse(items.data.enum) : [];
};
-export const TEAM_ADMIN_SETTINGS_FIELDS = ["tpm_limit", "rpm_limit", "max_budget"] as const;
+export const TEAM_ADMIN_SETTINGS_FIELDS = ["tpm_limit", "rpm_limit", "max_budget", "soft_budget"] as const;
export type TeamAdminSettingsField = (typeof TEAM_ADMIN_SETTINGS_FIELDS)[number];
@@ -56,6 +56,7 @@ const TEAM_ADMIN_FIELD_LABELS: ReadonlyMap<string, string> = new Map([
["tpm_limit", "Tokens per minute Limit (TPM)"],
["rpm_limit", "Requests per minute Limit (RPM)"],
["max_budget", "Max Budget (USD)"],
+ ["soft_budget", "Soft Budget (USD)"],
[TEAM_ADMIN_RAISE_MAX_BUDGET_PERMISSION, "Raise the team's max budget"],
["projects", "Create and update projects"],
["member_key_budgets", "Update budgets on team members' keys"],