Skip to main content

Virtual key budgets

A virtual key budget caps what one LiteLLM API key spends, in USD. Every request made with the key adds its cost to the key's spend, and once spend reaches the key's max_budget the key's requests fail until the budget resets or someone raises it. A key without a max_budget has no key cap, which is the default.

Spend on a key also counts toward the scopes above it: the key's team, the team member who owns it, its project and its organization, and the owner's personal budget when the key has no team or general_settings.apply_user_budget_to_team_keys is on. LiteLLM checks every budget that applies and rejects the request when any one of them is over its cap, so a key with room left is still blocked once its team runs out. Budget precedence lists which caps apply to each kind of key.

When to use it​

Give a key a budget when the key is the thing you want to stop: one key per application, CI pipeline, contractor or agent, so a runaway loop ends at that key without blocking the team's other keys. Add a reset period for an allowance that renews, such as $50 a month for an integration, and leave it out for a one-off grant that ends once it is spent, such as a trial key.

To cap a person across all of their keys, use an internal user budget or a team member budget instead. To cap many keys together, put them in a team or project and budget that. To give many keys the same limits that you can change in one place, link them to a shared budget.

Set a budget​

Pass max_budget in USD when you create the key, or later with /key/update. The key is blocked once its spend reaches the cap, so a max_budget of 0 blocks every request except those to free models.

curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H 'Content-Type: application/json' \
-d '{"key_alias": "ci-pipeline", "max_budget": 10}'

Pass team_id as well to have the key draw on a team's budget too. A caller who is not a proxy admin cannot give a new key a max_budget above the max_budget of the key they call with, and gets a 400.

Reset the budget on a schedule​

budget_duration sets the key's spend back to zero at the end of each period. Without it the budget never resets.

curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H 'Content-Type: application/json' \
-d '{"key_alias": "ci-pipeline", "max_budget": 10, "budget_duration": "30d"}'

Durations take seconds ("30s"), minutes ("30m"), hours ("1h"), days ("30d"), weeks ("1w") or months ("1mo"). Resets land on calendar boundaries in the configured timezone, so 30d and 1mo reset on the first of the month. Budget reset times and timezones covers when a reset happens. In the Admin UI, Reset Budget offers hourly, daily, weekly, monthly and annual periods.

Soft budget​

soft_budget never blocks a request. LiteLLM alerts when the key's spend crosses it, as described in Soft budgets and budget alerts. Set it on /key/generate or /key/update, or as Soft Budget (USD) when you edit the key in the Admin UI.

budget_id points the key at a budget row created with /budget/new. The row's max_budget applies when the key has none of its own, the key's own max_budget wins when both are set, and the key's soft_budget always comes from the row. A key without its own budget_duration resets when the row's period ends. Each key on the row still counts its own spend. See Shared budgets.

curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H 'Content-Type: application/json' \
-d '{"key_alias": "pro-tier-app", "budget_id": "pro-tier"}'

Several caps on one key​

budget_limits puts several caps on one key at once, such as $10 a day and $100 a month, each tracked and reset on its own schedule. See Multiple budget windows. model_max_budget sets a separate budget for each model the key can call, for example a small daily cap on gpt-6.1-sol and a larger monthly one on gpt-6-luna. See Per-model budgets, and Budget fallbacks to reroute instead of rejecting.

Check spend​

/key/info returns the key's budget fields. Called with the key itself, it reports on that key, and an admin can pass ?key= with the key or its hash.

curl 'http://0.0.0.0:4000/key/info' \
-H 'Authorization: Bearer sk-...'
{
"info": {
"key_alias": "ci-pipeline",
"spend": 7.42,
"total_spend": 31.9,
"max_budget": 10.0,
"budget_duration": "30d",
"budget_reset_at": "2030-02-01T00:00:00+00:00",
"model_spend": {"gpt-6-luna": 7.42}
}
}

spend covers the current period only, total_spend is lifetime spend that never resets, model_spend breaks spend down by model, and budget_reset_at is when the current period ends. max_budget is the key's own value, so a key that takes its cap from a shared budget shows it under litellm_budget_table instead. In the Admin UI, open the key from Virtual Keys, where the Overview tab shows spend for this period, when it resets, and lifetime spend.

Successful responses on the OpenAI-shaped routes also carry x-litellm-key-max-budget when the key has a cap, x-litellm-key-spend with the key's spend including this response, and x-litellm-response-cost with this response's cost. With several workers x-litellm-key-spend can trail what other workers just recorded, so treat /key/info as the authoritative value. See Response headers.

What callers get when it runs out​

A request made with a key that has reached its budget fails before LiteLLM calls the provider:

{
"error": {
"message": "Budget has been exceeded! Key=ci-pipeline (sk-...abcd) Current cost: 10.02, Max budget: 10.0",
"type": "budget_exceeded",
"param": null,
"code": "422"
}
}

The message names the key by its alias, or key when it has none, followed by the key's masked name. A budget_limits window fails with ExceededBudget: Key over 1d budget. instead. The status is 422 by default. See Budget exceeded errors to change it and to tell a budget refusal from a provider error.

Change or remove a budget​

Send new values to /key/update. Changing max_budget keeps the key's current spend, so a cap lowered below what the key has already spent blocks its next request. A different budget_duration starts a new period with a new budget_reset_at, without clearing spend, and resending the current one leaves the date alone.

curl -X POST 'http://0.0.0.0:4000/key/update' \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H 'Content-Type: application/json' \
-d '{"key": "sk-...", "max_budget": 25, "budget_duration": "1mo"}'

Send "max_budget": null to remove the cap and "budget_duration": null to stop resets. When upperbound_key_generate_params sets a max_budget, /key/update rejects a higher value or a null with a 400. In the Admin UI, open the key from Virtual Keys, go to Settings, select Edit Settings, change Max Budget (USD), Soft Budget (USD) or Reset Budget, and select Save Changes.

To clear spend without changing the cap, a proxy admin or an admin of the key's team can call /key/{key}/reset_spend with reset_to, a value from zero up to the current spend and no higher than the key's budget. It also restarts the key's budget_limits windows.

curl -X POST 'http://0.0.0.0:4000/key/sk-.../reset_spend' \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H 'Content-Type: application/json' \
-d '{"reset_to": 0}'

Proxy admins can change any key's budget. Team admins, team members and the key's own creator can change it only in the cases Self-serve budget changes lists, which includes the self_serve_budget_policy setting that lets key owners lower or, within limits, raise their own key's cap. For a short-term raise that expires on its own, use a temporary budget increase.

Default budget​

A key created without a budget has no key cap. litellm_settings.default_key_generate_params gives keys created through /key/generate and /key/service-account/generate a max_budget and budget_duration when the request leaves them out, and upperbound_key_generate_params fills anything still unset with its ceiling and rejects requests above it.

litellm_settings:
default_key_generate_params:
max_budget: 10
budget_duration: "30d"
upperbound_key_generate_params:
max_budget: 100

Keys that /user/new creates for a new user read neither setting, and Admin UI login session keys are capped by max_ui_session_budget, $1 by default. See Default budgets.

Budget features​

Which budget features work on virtual key budgets. Each feature page lists every scope it supports.

FeatureSupportedDetails
Shared budgetsYesbudget_id on /key/generate or /key/update. The key's own max_budget, tpm_limit, rpm_limit and model_max_budget win over the row's.
Default budgetsYesdefault_key_generate_params, then upperbound_key_generate_params for anything still unset. max_ui_session_budget caps Admin UI session keys.
Per-model budgetsYesmodel_max_budget on /key/generate or /key/update, or on a /budget/new row the key references with budget_id when the key sets none of its own.
Multiple budget windowsYesbudget_limits on /key/generate or /key/update, or Budget Windows in the key form.
Budget reset times and timezonesYesbudget_duration on /key/generate or /key/update, and each window in its budget_limits. Per-model budgets on the key count from their first request and ignore both settings.
Budget rollover, overage carry-overYesCarries over for the key's max_budget, its linked budget row and each budget_limits window.
Budget rollover, unused budget carry-overNoKeys have no rollover_max_budget.
Soft budgets and budget alertsYessoft_budget on /key/generate or /key/update alerts Slack and webhooks and emails the key owner. max_budget sends Slack and webhook alerts at 15% and 5% left and when crossed, and emails the owner at 80% or at the percentages in metadata.max_budget_alert_emails.
Team soft budget alertsNoA key's soft_budget alerts through general_settings.alerting and the key owner's email. See Soft budgets and budget alerts.
Budget exceeded errorsYesBudget has been exceeded! Key=<key_alias> (sk-...abcd), or ExceededBudget: Key over 1d budget. for a budget_limits window
Throttle over-budget keysYesthrottle_on_budget_exceeded: true on /key/generate or /key/update, plus litellm_settings.budget_exceeded_throttle_percentage. Covers the key's own max_budget only. A budget_limits window or a per-model budget on the key still rejects.
Budget fallbacksYesbudget_fallbacks on /key/generate or /key/update. It acts on the key's own model_max_budget, including one the key takes from its budget_id row.
Temporary budget increaseYestemp_budget_increase and temp_budget_expiry on /key/update. Only works on a key that has a max_budget
Budget reservationYesHolds against the key's max_budget, or its shared budget row's, and each of its budget_limits windows.
Fail-closed budget enforcementYesgeneral_settings.fail_closed_budget_enforcement: true. Covers max_budget and budget_limits windows.
Free models and budgetsYesThe key's max_budget, budget_limits windows and model_max_budget are not checked.
Self-serve budget changesYesself_serve_budget_policy under general_settings. Covers max_budget, budget_limits and budget_duration on /key/update and /key/regenerate, for the key's creator and owner

Limits​

A key's soft_budget is stored on its budget row. On /key/generate, a soft_budget makes LiteLLM create a private row for the key, which replaces a budget_id sent in the same request, so give a key on a shared row its soft budget through the row itself. On /key/update, a soft_budget on a key linked to a shared row changes that row, and with it every key on the row.

default_key_generate_params and upperbound_key_generate_params write their max_budget onto the key itself, so a key created with a budget_id uses that value instead of the row's unless the request sets its own.

A key with throttle_on_budget_exceeded: true keeps serving past its max_budget at reduced speed instead of failing. See Throttle over-budget keys.

Key budgets are enforced against spend in the database, so they cap nothing on a proxy without one, where virtual keys cannot be resolved at all.

Virtual keys covers creating and managing keys, Team budgets and Internal user budgets cap the scopes above a key, and Budgets and spend limits covers every other scope.