litellm/litellm/integrations/SlackAlerting
Nate Armstrong ead221995e
refactor(router): move router callers onto the entry points and invert the proxy imports (#48847)
Code outside the router now reaches it only through the entry points
(registry, settings, health, select, apply, observe, register_plugin, retire)
or the endpoint methods; the outside-member allowlist shrinks from 139 to 45.
litellm/router.py no longer imports litellm.proxy: it asks the installed
RouterHost (litellm/router_host.py) for vertex pass-through credentials,
member auto-router authorization and auto-router prompt compression, and the
proxy installs its host on import. Call sites where a model name can be
missing keep the old answer instead of reaching an entry point with None.
2026-10-29 17:26:33 +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 refactor(types): move slack alerting leaf types out of proxy/_types.py (#45752) 2026-10-10 19:06:22 +00:00
hanging_request_check.py refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -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 refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
user_spend_alerts.py refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -07:00
utils.py refactor: expose core private helpers under public names (#44871) 2026-10-07 00:05:27 +00: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