diff --git a/litellm/integrations/SlackAlerting/slack_alerting.py b/litellm/integrations/SlackAlerting/slack_alerting.py index c6150a69e63..5970f8cfb9d 100644 --- a/litellm/integrations/SlackAlerting/slack_alerting.py +++ b/litellm/integrations/SlackAlerting/slack_alerting.py @@ -1422,6 +1422,8 @@ Model Info: Returns -> True if sent, False if not. """ + if webhook_event.event == "soft_budget_crossed" and webhook_event.event_group == Litellm_EntityType.USER: + return False from litellm.proxy.proxy_server import premium_user from litellm.proxy.utils import send_email diff --git a/litellm/proxy/management_helpers/bulk_user_creation.py b/litellm/proxy/management_helpers/bulk_user_creation.py index 77e37cb11cb..7655e228362 100644 --- a/litellm/proxy/management_helpers/bulk_user_creation.py +++ b/litellm/proxy/management_helpers/bulk_user_creation.py @@ -114,6 +114,7 @@ class _UserRow(LiteLLMBaseModel): user_role: str | None = None team_id: str | None = None max_budget: float | None = None + soft_budget: float | None = None spend: float | None = 0.0 models: tuple[str, ...] | None = None metadata: Mapping[str, object] | None = None @@ -375,6 +376,7 @@ class _UserCreateData(TypedDict): user_role: ReadOnly[str | None] team_id: ReadOnly[str | None] max_budget: ReadOnly[float | None] + soft_budget: ReadOnly[float | None] spend: ReadOnly[float] models: ReadOnly[tuple[str, ...]] metadata: ReadOnly[str] @@ -409,6 +411,7 @@ def _user_create_payload(prepared: _PreparedUser) -> _UserCreateData: "user_role": row.user_role, "team_id": row.team_id, "max_budget": row.max_budget, + "soft_budget": row.soft_budget, "spend": row.spend or 0.0, "models": row.models or (), "metadata": metadata_json, diff --git a/tests/unit/integrations/SlackAlerting/test_slack_alerting.py b/tests/unit/integrations/SlackAlerting/test_slack_alerting.py index 84c85e1d402..d730c8ccd6d 100644 --- a/tests/unit/integrations/SlackAlerting/test_slack_alerting.py +++ b/tests/unit/integrations/SlackAlerting/test_slack_alerting.py @@ -1326,3 +1326,35 @@ def test_budget_email_escapes_user_id() -> None: assert " None: + import litellm.proxy.utils as proxy_utils + from litellm.proxy._types import WebhookEvent + + sent: Final[list[str]] = [] + + async def record_email(receiver_email: str, subject: str, html: str) -> None: + sent.append(receiver_email) + + monkeypatch.setattr(proxy_utils, "send_email", record_email) + event: Final = WebhookEvent( + spend=6, + soft_budget=5, + user_id="u1", + user_email="u1@example.com", + token="hashed-token", + event="soft_budget_crossed", + event_group=event_group, + event_message="Soft budget crossed", + ) + + await SlackAlerting(alerting=["email"]).send_email_alert_using_smtp(webhook_event=event, alert_type="budget_alerts") + + assert sent == recipients diff --git a/tests/unit/proxy/management_helpers/test_bulk_user_creation.py b/tests/unit/proxy/management_helpers/test_bulk_user_creation.py index 96c84578111..80c1c7fed82 100644 --- a/tests/unit/proxy/management_helpers/test_bulk_user_creation.py +++ b/tests/unit/proxy/management_helpers/test_bulk_user_creation.py @@ -212,7 +212,7 @@ async def test_creates_users_and_team_membership_in_every_store(): response = await _run( prisma, [ - {"user_id": "u1", "user_email": "a@example.com", "teams": ["t1", "t2"], "max_budget": 50}, + {"user_id": "u1", "user_email": "a@example.com", "teams": ["t1", "t2"], "max_budget": 50, "soft_budget": 20}, {"user_id": "u2", "user_email": "b@example.com", "teams": ["t1"]}, {"user_id": "u3", "user_email": "c@example.com"}, ], @@ -225,6 +225,7 @@ async def test_creates_users_and_team_membership_in_every_store(): users = prisma.db.litellm_usertable.rows assert users["u1"].teams == ["t1", "t2"] and users["u1"].max_budget == 50 + assert users["u1"].soft_budget == 20 and getattr(users["u2"], "soft_budget", None) is None assert users["u2"].teams == ["t1"] and users["u3"].teams == [] assert [m.user_id for m in prisma.db.litellm_teamtable.rows["t1"].members_with_roles] == ["existing", "u1", "u2"] assert [m.user_id for m in prisma.db.litellm_teamtable.rows["t2"].members_with_roles] == ["u1"]