mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-23 22:07:29 +00:00
* refactor(types): move LitellmUserRoles and KeyManagementRoutes into litellm.types.proxy.auth.user_roles Part of LIT-9423 * refactor(types): move is_jwt into litellm.types.proxy.auth.user_api_key_auth Part of LIT-9423 * refactor(auth): alias is_jwt import so JWTHandler.is_jwt is not read as recursive * refactor(types): type UserAPIKeyAuth, its token view and hash_token in place Part of LIT-9423 * refactor(types): move UserAPIKeyAuth, its token view and hash_token into litellm.types.proxy.auth.user_api_key_auth Part of LIT-9423 * fix(types): keep agent, budget snapshot and is_jwt names importable from proxy._types Part of LIT-9423 * refactor(sdk): import UserAPIKeyAuth from litellm.types.proxy.auth Part of LIT-9423 * fix(types): restore main's _types.py content alongside the user_api_key_auth move Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(sdk): resolve litellm.proxy lazily on attribute access The layer cleanup stopped import litellm from loading any proxy module, so litellm.proxy was no longer bound and litellm.proxy._types.X raised AttributeError. The module __getattr__ now imports litellm.proxy on first access, which keeps import litellm free of proxy._types and fixes the docs and code-quality checks on main * fix(sdk): resolve litellm.proxy lazily on attribute access The layer cleanup stopped import litellm from loading any proxy module, so litellm.proxy was no longer bound and litellm.proxy._types.X raised AttributeError. The module __getattr__ now imports litellm.proxy on first access, which keeps import litellm free of proxy._types and fixes the docs and code-quality checks on main * style(types): drop blank lines between proxy._types re-export imports Part of LIT-9423 * refactor(proxy): keep only user_api_key_auth re-exports in _types.py Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(proxy): carry main's UserAPIKeyAuth field into moved file Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * style(types): drop blank lines between proxy._types re-export imports Part of LIT-9423 * fix(types): drop unused TypeIs import from proxy/_types.py --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| batching_handler.py | ||
| budget_alert_types.py | ||
| hanging_request_check.py | ||
| ms_teams.py | ||
| Readme.md | ||
| slack_alerting.py | ||
| user_spend_alerts.py | ||
| utils.py | ||
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 alertsbatching_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 traffictypes.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 alertget_event_message(): Returns the message prefix for the alertget_id(user_info): Returns the ID to use for caching/tracking the alert
Concrete implementations include:
ProxyBudgetAlert: Alerting for proxy-level budget concernsSoftBudgetAlert: Alerting when soft budgets are crossedUserBudgetAlert: Alerting for user-level budget concernsTeamBudgetAlert: Alerting for team-level budget concernsTokenBudgetAlert: Alerting for API key budget concernsProjectedLimitExceededAlert: 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.