---
title: "Virtual key budgets"
url: "/docs/proxy/key_budgets"
canonical_url: "https://docs.litellm.ai/docs/proxy/key_budgets"
type: "docs"
last_updated: "2026-12-02"
summary: "Cap what one LiteLLM virtual key can spend with max_budget and an optional reset period, set by admins and, within limits, by key owners."
related:
  - "/docs/proxy/project_management"
  - "/docs/proxy/internal_user_budgets"
---
# Virtual key budgets

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


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](./team_budgets.md), the [team member](./team_member_budgets.md) who owns it, its [project](./project_management.md) and its [organization](./organization_budgets.md), and the owner's [personal budget](./internal_user_budgets.md) 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](./access_management/inheritance.md#budgets) 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](./internal_user_budgets.md) or a [team member budget](./team_member_budgets.md) 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](./shared_budgets.md).

## Set a budget {#add-budgets-to-keys}

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](./free_model_budgets.md).

**API**

```bash
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.

**Admin UI**

Open **Virtual Keys**, select **+ Create New Key**, expand **Optional Settings**, and set **Max Budget (USD)** and **Reset Budget** under **Budget Settings**. When the key belongs to a team, the form does not accept a budget above the team's.

### Reset the budget on a schedule {#add-budget-duration-to-keys}

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

```bash
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](./budget_reset_and_tz.md) 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](./budget_alerts.md). Set it on `/key/generate` or `/key/update`, or as **Soft Budget (USD)** when you edit the key in the Admin UI.

### Link a shared budget

`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](./shared_budgets.md).

```bash
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 {#set-multiple-budget-windows-on-a-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](./budget_windows.md). `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](./per_model_budgets.md#virtual-key), and [Budget fallbacks](./budget_fallbacks.md) 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.

```bash
curl 'http://0.0.0.0:4000/key/info' \
  -H 'Authorization: Bearer sk-...'
```

```json
{
  "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](./response_headers.md).

### What callers get when it runs out

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

```json
{
  "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](./budget_exceeded_errors.md) 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.

```bash
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.

```bash
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](./self_serve_budgets.md) 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](./temporary_budget_increase.md).

## 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.

```yaml
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](./default_budgets.md#keys).

## Budget features

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

| Feature | Supported | Details |
| --- | --- | --- |
| [Shared budgets](./shared_budgets.md) | Yes | `budget_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 budgets](./default_budgets.md) | Yes | `default_key_generate_params`, then `upperbound_key_generate_params` for anything still unset. `max_ui_session_budget` caps Admin UI session keys. |
| [Per-model budgets](./per_model_budgets.md) | Yes | `model_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 windows](./budget_windows.md) | Yes | `budget_limits` on `/key/generate` or `/key/update`, or **Budget Windows** in the key form. |
| [Budget reset times and timezones](./budget_reset_and_tz.md) | Yes | `budget_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](./budget_rollover.md), overage carry-over | Yes | Carries over for the key's `max_budget`, its linked budget row and each `budget_limits` window. |
| [Budget rollover](./budget_rollover.md), unused budget carry-over | No | Keys have no `rollover_max_budget`. |
| [Soft budgets and budget alerts](./budget_alerts.md) | Yes | `soft_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 alerts](./ui_team_soft_budget_alerts.md) | No | A key's `soft_budget` alerts through `general_settings.alerting` and the key owner's email. See [Soft budgets and budget alerts](./budget_alerts.md#set-a-soft-budget). |
| [Budget exceeded errors](./budget_exceeded_errors.md) | Yes | `Budget has been exceeded! Key=<key_alias> (sk-...abcd)`, or `ExceededBudget: Key over 1d budget.` for a `budget_limits` window |
| [Throttle over-budget keys](./budget_throttling.md) | Yes | `throttle_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 fallbacks](./budget_fallbacks.md) | Yes | `budget_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 increase](./temporary_budget_increase.md) | Yes | `temp_budget_increase` and `temp_budget_expiry` on `/key/update`. Only works on a key that has a `max_budget` |
| [Budget reservation](./budget_reservation.md) | Yes | Holds against the key's `max_budget`, or its shared budget row's, and each of its `budget_limits` windows. |
| [Fail-closed budget enforcement](./fail_closed_budgets.md) | Yes | `general_settings.fail_closed_budget_enforcement: true`. Covers `max_budget` and `budget_limits` windows. |
| [Free models and budgets](./free_model_budgets.md) | Yes | The key's `max_budget`, `budget_limits` windows and `model_max_budget` are not checked. |
| [Self-serve budget changes](./self_serve_budgets.md) | Yes | `self_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](./budget_throttling.md).

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.

## Related

[Virtual keys](./virtual_keys.md) covers creating and managing keys, [Team budgets](./team_budgets.md) and [Internal user budgets](./internal_user_budgets.md) cap the scopes above a key, and [Budgets and spend limits](./budgets.md) covers every other scope.

## Related pages

- [Projects](https://docs.litellm.ai/docs/proxy/project_management.md)
- [Internal users](https://docs.litellm.ai/docs/proxy/internal_user_budgets.md)
