litellm/litellm/integrations/SlackAlerting
devin-ai-integration[bot] d08746feb1
feat(proxy): email alerts at configured percentages of a team member budget (#42665)
* feat(proxy): email alerts at configured percentages of a team member budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(alerting): label team member budget crossings as team member budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(auth): cover the team member alert dispatch from _check_team_member_budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(email): drop the emoji from the team member budget alert template

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): ignore team member alert thresholds outside 1 to 100 on both the backend and the dashboard

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): bound team member alert threshold key length before int parsing

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(integration): drop the legacy covers marker from the team member alert test

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(team): reject malformed team_member_max_budget_alert_emails on team writes

Thresholds outside 1-100, non-list recipients, and invalid emails now return 422 on
/team/new, /team/update and PATCH /team/{id} instead of being stored and silently
ignored. The value is stored canonically. Read-side LiteLLM_TeamTable is unchanged,
and the PATCH body stays a raw merge patch so a null threshold still deletes it.

* fix(auth): enforce and alert on team member budgets only in common_checks

The builder re-checked the team member budget inline before common_checks ran the same
check, so one request that crossed a team_member_max_budget_alert_emails threshold
dispatched two alerts. Drop the inline check; common_checks is the single authorization
point and already covers per-member rows, the team default member budget, zero-cost
skips and the cross-pod spend counter. Its 422 message now uses the TeamMember=user:team
form the builder and budget reservation already returned.

* Revert "fix(team): reject malformed team_member_max_budget_alert_emails on team writes"

This reverts commit 703e754b46.

* fix(alerting): keep BaseBudgetAlertType.get_event_message zero-arg

Requiring user_info broke existing callers and out-of-tree subclasses. The team member
label now comes from SlackAlerting.budget_alerts, so the interface and its Readme are
unchanged from main.

* fix(mcp): keep team member budget enforcement on the MCP OAuth auth dependency

The MCP OAuth dependency stops at _user_api_key_auth_builder and never reaches common_checks, so removing the builder's inline member budget check would have let over-budget members through there. Enforce it explicitly for that caller.

* fix(auth): keep main's team member budget enforcement, alert once per request

Restore the builder's team member budget check and 422 message exactly as on main and drop the MCP-only gate. The builder sends the member alert only on the request it rejects; common_checks sends it for requests that get past the builder, so no request alerts twice.

* test(integration): read team member alert deliveries without a shared accumulator

* test(integration): match team member alert deliveries by subject so other alerts cannot race the count

* refactor(proxy): build the team member alert threshold config without mutable collections

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(proxy): collapse the alert recipient isinstance checks into one call

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(integration): read the SMTP sink through lock-guarded snapshots and assert the exact deliveries

---------

Co-authored-by: ryan <ryan@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-26 02:42:45 +00:00
..
batching_handler.py fix(alerting): deliver every distinct alert queued in one flush window 2026-09-21 13:51:03 -07:00
budget_alert_types.py feat(proxy): email alerts at configured percentages of a team member budget (#42665) 2026-09-26 02:42:45 +00:00
hanging_request_check.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
ms_teams.py feat(alerting): add native Microsoft Teams alerting destination (#38367) 2026-08-27 16:19:22 -07:00
Readme.md [Fix + Refactor] Trigger Soft Budget Webhooks When Key Crosses Threshold (#10491) 2025-05-02 07:06:07 -07:00
slack_alerting.py feat(proxy): email alerts at configured percentages of a team member budget (#42665) 2026-09-26 02:42:45 +00:00
user_spend_alerts.py feat(alerting): slack alerts for per-user daily/monthly spend thresholds and spend anomaly detection (#38438) 2026-09-01 15:09:03 -07:00
utils.py feat(langfuse): migrate the sdk callback to langfuse v4 (#36741) 2026-09-24 23:22:56 -07:00

Slack Alerting on LiteLLM Gateway

This folder contains the Slack Alerting integration for LiteLLM Gateway.

Folder Structure

  • slack_alerting.py: This is the main file that handles sending different types of alerts
  • batching_handler.py: Handles Batching + sending Httpx Post requests to slack. Slack alerts are sent every 10s or when events are greater than X events. Done to ensure litellm has good performance under high traffic
  • types.py: This file contains the AlertType enum which is used to define the different types of alerts that can be sent to Slack.
  • utils.py: This file contains common utils used specifically for slack alerting

Budget Alert Types

The budget_alert_types.py module provides a flexible framework for handling different types of budget alerts:

  • BaseBudgetAlertType: An abstract base class with abstract methods that all alert types must implement:
    • get_event_group(): Returns the Litellm_EntityType for the alert
    • get_event_message(): Returns the message prefix for the alert
    • get_id(user_info): Returns the ID to use for caching/tracking the alert

Concrete implementations include:

  • ProxyBudgetAlert: Alerting for proxy-level budget concerns
  • SoftBudgetAlert: Alerting when soft budgets are crossed
  • UserBudgetAlert: Alerting for user-level budget concerns
  • TeamBudgetAlert: Alerting for team-level budget concerns
  • TokenBudgetAlert: Alerting for API key budget concerns
  • ProjectedLimitExceededAlert: Alerting when projected spend will exceed budget

Use the get_budget_alert_type() factory function to get the appropriate alert type class for a given alert type string:

from litellm.integrations.SlackAlerting.budget_alert_types import get_budget_alert_type

# Get the appropriate handler
budget_alert_class = get_budget_alert_type("user_budget")

# Use the handler methods
event_group = budget_alert_class.get_event_group()  # Returns Litellm_EntityType.USER
event_message = budget_alert_class.get_event_message()  # Returns "User Budget: "
cache_id = budget_alert_class.get_id(user_info)  # Returns user_id

To add a new budget alert type, simply create a new class that extends BaseBudgetAlertType and implements all the required methods, then add it to the dictionary in the get_budget_alert_type() function.

Further Reading