[Feature]: Support aggregate shared-wallet budget fallback to economy models
The feature
Add native support for applying fallback models when an aggregate virtual-key, user, team-member, or team budget reaches a configured threshold.
The requested behaviour is:
- A key has access to many model groups, for example 20 or more models.
- All paid models draw from one shared aggregate allowance, for example USD 10 per 30 days.
- When the shared allowance is exhausted, paid-model requests are transparently rerouted to one of the configured zero-cost or economy fallback models.
- Requests to the fallback models continue without returning
429 budget_exceeded. - All budget enforcement remains inside the LiteLLM proxy.
This is different from the current per-model model_max_budget behaviour.
The requirement is one shared wallet across all eligible paid models, not a
separate budget for every model.
Current behaviour
LiteLLM currently provides:
max_budget, which aggregates key spend but returns429 budget_exceededwhen exhausted.soft_budget, which triggers alerts but does not change routing, model access, or rate limits.model_max_budgetwithbudget_fallbacks, which supports fallback only when an individual model's budget is exhausted.
budget_fallbacks does not currently activate when the aggregate key
max_budget is exceeded.
Reproduction
Key configuration
Example, simplified:
{
"max_budget": 0.02,
"budget_duration": "30d",
"models": [
"premium-model-a",
"premium-model-b",
"premium-model-c",
"gpt-5.4-mini-free-fallback"
],
"budget_fallbacks": {
"premium-model-a": [
"gpt-5.4-mini-free-fallback"
]
}
}The fallback model is registered and available to the key.
Request
curl -X POST "$LITELLM_PROXY/v1/chat/completions" \
-H "Authorization: Bearer <redacted-virtual-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "premium-model-a",
"messages": [
{
"role": "user",
"content": "Write a short test essay."
}
]
}'Actual result
HTTP 429 budget_exceeded
Budget has been exceeded!
Current cost: 0.0214
Max budget: 0.02The request does not fall back to gpt-5.4-mini-free-fallback.
Expected result
Once aggregate paid spend reaches max_budget, a request for any paid model should be rerouted to the first eligible aggregate-budget fallback model:
premium-model-a
-> aggregate wallet exhausted
-> gpt-5.4-mini-free-fallbackThe fallback request should succeed if:
- the fallback model is allowed for the key;
- the fallback model is configured as an aggregate-budget fallback;
- the fallback model has no exhausted applicable budget;
- the fallback model meets any configured zero-cost or economy-model policy.
Why model_max_budget is not sufficient
The deployment exposes more than 20 approved models to each user.
Dividing a USD 1 or USD 10 allowance across 20 or more separate model_max_budget entries:
- fragments the user's allowance;
- leaves unused budget stranded against models the user never selects;
- permits total spending above the intended allowance if the full allowance is assigned independently to every model;
- creates substantial configuration and lifecycle overhead;
- does not provide a genuine shared wallet.
The desired semantic is:
One key
One aggregate paid-model wallet
Many paid models
One ordered economy fallback chainProposed configuration
One possible key-level API:
{
"max_budget": 10.0,
"budget_duration": "30d",
"aggregate_budget_fallbacks": [
"gpt-5.4-mini-free-fallback",
"qwen-economy-fallback"
]
}Alternative naming:
{
"budget_fallbacks": {
"*": [
"gpt-5.4-mini-free-fallback",
"qwen-economy-fallback"
]
}
}The explicit aggregate_budget_fallbacks field may be safer because it avoids changing the current semantics of budget_fallbacks, which is keyed by primary model and linked to model_max_budget.
Optional soft-threshold extension
It would also be useful to support an action at soft_budget, not only an alert:
{
"soft_budget": 10.0,
"max_budget": 12.0,
"soft_budget_action": {
"type": "fallback",
"models": [
"gpt-5.4-mini-free-fallback",
"qwen-economy-fallback"
]
}
}Possible action types could include:
alert, preserving current behaviour;fallback, rerouting paid requests to configured economy models;throttle, applying post-threshold RPM/TPM limits;block, if explicit soft-threshold enforcement is required.
Requested scopes
Ideally this should be supported at:
- virtual-key budget;
- user budget;
- team-member budget;
- team budget;
- organisation budget.
The initial implementation could start with virtual-key aggregate budgets.
Enforcement considerations
The implementation should:
- Perform the aggregate-budget check before selecting a paid deployment.
- Permit only fallback targets allowed by the key/team model-access policy.
- Avoid recursively routing from one exhausted paid fallback to another uncontrolled paid model.
- Re-evaluate the applicable budget if the fallback target is not zero-cost.
- Attribute post-fallback usage to the actual fallback model.
- Emit structured metadata indicating:
- requested model;
- resolved model;
- budget scope;
- threshold crossed;
- fallback reason.
- Support Redis/shared state for multi-worker deployments.
- Avoid race conditions where concurrent requests significantly overspend the aggregate allowance.
- Preserve the existing
model_max_budgetand router-failure fallback semantics.
Acceptance criteria
- A key can access 20 or more paid model groups under one shared aggregate budget.
- Spending through any paid model contributes to the same budget.
- After the threshold is reached, requests to any paid model route to a configured economy fallback.
- No
429 budget_exceededis returned while an eligible aggregate-budget fallback is available. - Direct calls to eligible fallback models continue to work.
- If every fallback is unavailable, disallowed, or budget-exhausted, LiteLLM returns the normal budget error.
- Usage logs distinguish the requested and resolved model.
- Behaviour is covered by unit and multi-worker concurrency tests.
Deployment context
- LiteLLM Proxy with PostgreSQL-backed virtual keys and spend tracking
- One personal virtual key per user
- More than 20 approved model groups
- Shared personal allowance, for example USD 1 or USD 10 per reset period
- Economy or zero-cost models available for continued access
- Requirement that enforcement remain within LiteLLM rather than an external portal or policy worker
Source: BerriAI/litellm