feature: support end_user_budget alerts to slack#22279
feature: support end_user_budget alerts to slack#22279huetterma wants to merge 4 commits intoBerriAI:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
57a10f9 to
b139fcd
Compare
Greptile SummaryThis PR adds Slack/webhook budget alerting support for
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/auth_checks.py | Core change: decoupled _check_end_user_budget from get_end_user_object, converted to async, added Slack/webhook budget alerting for both max and soft budgets, and moved budget enforcement into common_checks. Exception handler in get_end_user_object simplified appropriately. |
| litellm/integrations/SlackAlerting/budget_alert_types.py | New EndUserBudgetAlert class added following the same pattern as other alert types. Uses customer_id for ID tracking. Registered in factory function. |
| litellm/integrations/SlackAlerting/slack_alerting.py | Added "end_user_budget" to the Literal type union for the budget_alerts method. Minimal, correct change. |
| litellm/proxy/utils.py | Added "end_user_budget" to the Literal type union in ProxyLogging.budget_alerts. Minimal, correct change. |
| tests/test_litellm/integrations/SlackAlerting/test_budget_alert_types.py | Added TestEndUserBudgetAlert class with tests for get_event_message and get_id with various customer_id states. Uses only mocks, no network calls. |
| tests/test_litellm/proxy/auth/test_auth_checks.py | Comprehensive TestCheckEndUserBudget class with 8 tests covering max budget alerts, soft budget alerts, no-proxy-logging fallback, info route skipping, missing budget table, and combined max+soft budget scenarios. All use mocks. |
| tests/proxy_unit_tests/test_auth_checks.py | Updated test_get_end_user_object to reflect the new architecture: get_end_user_object returns the object without raising, then _check_end_user_budget is called separately for budget enforcement. |
| tests/proxy_unit_tests/test_default_end_user_budget_simple.py | Updated test_budget_enforcement_blocks_over_budget_users to reflect the decoupled architecture: fetch via get_end_user_object, then enforce via _check_end_user_budget. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[common_checks] --> B{end_user_object is not None?}
B -->|No| Z[Continue to next check]
B -->|Yes| C["_check_end_user_budget()"]
C --> D{litellm_budget_table is None?}
D -->|Yes| Z
D -->|No| E{spend > max_budget?}
E -->|Yes| F["Fire 'end_user_budget' alert via asyncio.create_task"]
F --> G["Raise BudgetExceededError"]
E -->|No| H{spend >= soft_budget?}
H -->|Yes| I["Fire 'end_user_budget' soft alert via asyncio.create_task"]
I --> Z
H -->|No| Z
Last reviewed commit: 9dbd349
Additional Comments (1)
Since |
Relevant issues
Expected to see slack alerts when my
end_usersare exceeding spend limit when they have a budget attached. But nothing happened, so went into the code to see if we already support alerting forend_users. No support for alerting currently, this addresses this.Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
Changes
Introducing a
end_user_budgetalert to slack for alerting.Decoupled
_check_end_user_budgetfromget_end_user_objectas they serve different functionality