fix: custom auth budget issue - #22164
Merged
Harshit28j merged 2 commits intoFeb 26, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
@greptile please review this PR |
Harshit28j
marked this pull request as ready for review
February 26, 2026 07:52
Contributor
Greptile SummaryThis PR adds end-user per-model budget enforcement for custom auth flows in the LiteLLM proxy. Previously, custom auth functions returning Key changes:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/user_api_key_auth.py | Core change: adds _run_post_custom_auth_checks and _lookup_end_user_and_apply_budget to run budget/auth checks after custom auth returns. Also fixes update_valid_token_with_end_user_params to not override custom-auth-set values with None. Well-structured and follows existing patterns. |
| litellm/proxy/hooks/model_max_budget_limiter.py | Adds is_end_user_within_model_budget and _get_end_user_spend_for_model methods mirroring the existing virtual key pattern. Also extends async_log_success_event to track end-user per-model spend. Implementation follows existing patterns correctly. |
| litellm/proxy/_types.py | Adds end_user_model_max_budget: Optional[dict] to LiteLLM_VerificationTokenView. Remaining changes are formatting-only (auto-formatter adjustments). |
| litellm/proxy/litellm_pre_call_utils.py | Passes end_user_model_max_budget into request metadata so async_log_success_event can track spend. Remaining changes are import formatting only. |
| tests/proxy_unit_tests/test_unit_test_max_model_budget_limiter.py | Adds tests for is_end_user_within_model_budget, _get_end_user_spend_for_model, and end-user budget tracking in async_log_success_event. All properly mocked with no network calls. |
| tests/test_litellm/proxy/auth/test_custom_auth_end_user_budget.py | New test file covering _run_post_custom_auth_checks and update_valid_token_with_end_user_params. Tests verify custom auth budget values aren't overridden by None DB values, and that budget exceeded errors propagate correctly. All mocked, no network calls. |
Sequence Diagram
sequenceDiagram
participant Client
participant CustomAuth as Custom Auth Function
participant PostChecks as _run_post_custom_auth_checks
participant DB as DB / Cache
participant BudgetLimiter as ModelMaxBudgetLimiter
Client->>CustomAuth: Request with API key
CustomAuth-->>PostChecks: UserAPIKeyAuth (with end_user_id, end_user_model_max_budget)
PostChecks->>DB: Look up end_user object (if end_user_id set)
DB-->>PostChecks: end_user_object + budget table
Note over PostChecks: update_valid_token_with_end_user_params<br/>(only overwrite if DB value is not None)
PostChecks->>PostChecks: Check token expiry
PostChecks->>BudgetLimiter: is_key_within_model_budget (key-level)
BudgetLimiter-->>PostChecks: OK / BudgetExceededError
PostChecks->>BudgetLimiter: is_end_user_within_model_budget (end-user-level)
BudgetLimiter->>DB: Get cached spend for end_user + model
DB-->>BudgetLimiter: current_spend
BudgetLimiter-->>PostChecks: OK / BudgetExceededError
PostChecks->>PostChecks: common_checks (team, user, org budgets)
PostChecks-->>Client: UserAPIKeyAuth / Error
Last reviewed commit: 39af85d
Contributor
Author
|
@greptile please review this PR |
Harshit28j
added a commit
to Harshit28j/litellm
that referenced
this pull request
Mar 3, 2026
…_run_common_checks Replaces the skip_route_check approach from PR BerriAI#22662 with a configurable opt-in flag. By default, common_checks() is not run for custom auth flows, preserving backwards compatibility with pre-BerriAI#22164 behavior. Users who want budget/team/route enforcement on custom auth can enable it: general_settings: custom_auth_run_common_checks: true Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…budget_fix fix: custom auth budget issue
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…_run_common_checks Replaces the skip_route_check approach from PR BerriAI#22662 with a configurable opt-in flag. By default, common_checks() is not run for custom auth flows, preserving backwards compatibility with pre-BerriAI#22164 behavior. Users who want budget/team/route enforcement on custom auth can enable it: general_settings: custom_auth_run_common_checks: true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.