---
title: "Fail-closed budget enforcement"
url: "/docs/proxy/fail_closed_budgets"
canonical_url: "https://docs.litellm.ai/docs/proxy/fail_closed_budgets"
type: "docs"
last_updated: "2026-12-02"
summary: "Reject budgeted requests with a 503 when their spend cannot be verified against Redis or the database, so a budget stays a hard ceiling during outages."
related:
  - "/docs/proxy/temporary_budget_increase"
  - "/docs/proxy/self_serve_budgets"
---
# Fail-closed budget enforcement

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


Available in LiteLLM v1.90.0 and later.

Budget checks read current spend from a counter in Redis that every worker and replica shares, and the database catches up in the background. When Redis restarts from an older snapshot or becomes unreachable, that counter can read lower than what was really spent. By default LiteLLM still admits the request, falling back to the spend each worker holds in memory, which keeps traffic flowing but can let a budget run over. `general_settings.fail_closed_budget_enforcement: true` makes every budgeted request check its spend against the database as well, and rejects the request with a 503 when its spend can be verified against neither Redis nor the database.

LiteLLM also reserves each request's estimated cost against its budgets before it calls the provider, so a burst of concurrent requests cannot all pass a budget that only some of them fit. Reservation is on by default, with or without the setting. The setting makes it strict, so a request whose estimated cost does not fit the remaining budget is rejected up front (since LiteLLM v1.101.0), and a reservation that cannot be written rejects the request with a 503 (since LiteLLM v1.95.0).

## How it works

```mermaid
flowchart TD
  accTitle: Budget admission with fail-closed enforcement on
  accDescr: LiteLLM reads the spend counter. A request already over its cap is rejected with budget_exceeded. Otherwise it reads recorded spend from the database, cached for 5 seconds per worker. If neither Redis nor the database verified the spend, the request is rejected with 503. If the higher of the two is over the cap, it is rejected with budget_exceeded. Then the estimated cost is reserved. A failed reservation write returns 503, an estimate over the remaining budget returns budget_exceeded, and a successful reservation lets the request reach the provider.
  REQ["Budgeted request"] --> READ["Read the<br/>spend counter"]
  READ --> CAP1{"At or over<br/>the cap?"}
  CAP1 -->|Yes| OVER["Reject with<br/>budget_exceeded"]
  CAP1 -->|No| DB["Read recorded spend<br/>from the database<br/>(cached 5 s per worker)"]
  DB --> VER{"Verified by Redis<br/>or the database?"}
  VER -->|No| DOWN["Reject with 503"]
  VER -->|Yes| CAP2{"Higher of the two<br/>at or over the cap?"}
  CAP2 -->|Yes| OVER
  CAP2 -->|No| HOLD{"Reserve the<br/>estimated cost"}
  HOLD -->|Write failed| DOWN
  HOLD -->|Estimate over<br/>remaining budget| OVER
  HOLD -->|Reserved| CALL["Call the provider"]
  classDef default fill:#ffffff,stroke:#9ca3af,color:#111827;
```

With the setting off, LiteLLM reads the database only when the counter is missing, when it reads below the spend LiteLLM already has cached for that budget, or for a `budget_limits` window, so healthy traffic stays off the database. Spend that only this worker's memory holds is trusted, a reservation that cannot be written is skipped, and a request whose estimate is larger than what remains is admitted with its reservation cut down to the remaining budget. That last request can still land a little over the cap, since its actual cost can exceed the part that was reserved.

## When to use it

Turn it on when a budget is a hard spending ceiling, such as a customer's prepaid allowance, a cap that finance holds a team to, or a budget you bill against. It also fits deployments where Redis restarts or fails over without persistence, since a counter that comes back empty or from an old snapshot would otherwise under-report spend until the database catches up. In both cases a short burst of 503s during an outage is cheaper than spend you cannot recover.

Leave it off when staying up matters more than an exact cap. The default mode already re-checks the database whenever the counter reads below the spend LiteLLM knows about, which catches the common stale-counter case without a database read on every request. To cap throughput rather than spend during a Redis outage, use [`fail_closed_rate_limit_enforcement`](./rate_limits.md#hard-rate-limit-enforcement-fail-closed) instead.

## Supported scopes

Every scope marked Yes is also reserved before the call, except AI tools.

| Scope | Supported | How to set it |
| --- | --- | --- |
| Whole proxy | No | Proxy-wide spend is read from its own database row on a separate path that the setting does not change. |
| Organization | Yes | `general_settings.fail_closed_budget_enforcement: true`. |
| Team | Yes | `general_settings.fail_closed_budget_enforcement: true`. Covers `max_budget` and `budget_limits` windows. |
| Team member | Yes | `general_settings.fail_closed_budget_enforcement: true`. A member who has a team member budget but no membership row is rejected with a 403 until a team admin adds them with `/team/member_add`. |
| Project | Yes | `general_settings.fail_closed_budget_enforcement: true`. |
| Virtual key | Yes | `general_settings.fail_closed_budget_enforcement: true`. Covers `max_budget` and `budget_limits` windows. |
| Internal user | Yes | `general_settings.fail_closed_budget_enforcement: true`. Covers `max_budget` and `budget_limits` windows. |
| Customer | Yes | `general_settings.fail_closed_budget_enforcement: true`. Legacy end-user budgets are checked against the customer's database row. Customer Management budget windows reject with a 503 whenever their spend cannot be read, with or without the setting. |
| Tag | Yes | `general_settings.fail_closed_budget_enforcement: true`. Spend is checked against the tag's recorded spend, which is read along with the tag itself, so only a failed reservation returns a 503. |
| Model access group | Yes | `general_settings.fail_closed_budget_enforcement: true`. Same as tags. |
| AI tool | Yes | `general_settings.fail_closed_budget_enforcement: true`. Spend is checked against the AI tool budget row, but nothing is reserved, so concurrent requests can still overshoot. |
| Agent session | No | Session spend lives in its own counter that the setting does not read. |

## How to use it

### Turn it on

```yaml title="config.yaml"
general_settings:
  fail_closed_budget_enforcement: true
```

Keep budget reservation on, which is the default. `general_settings.disable_budget_reservation: true` turns reservation off, and then concurrent requests can pass a budget that only some of them fit even with fail-closed enforcement on, since each request is checked only against spend already recorded.

### What callers get

A request whose spend cannot be verified, or whose reservation cannot be written, returns HTTP 503 with `Budget enforcement unavailable` in its `error.message`. A Customer Management budget window whose spend cannot be read returns a 503 with `Customer budget window spend is unavailable.` instead. Treat either like any other 503 and retry with backoff once Redis or the database is back. Requests that carry no budget are never rejected this way.

A request whose estimated cost does not fit the remaining budget returns the regular [`budget_exceeded` error](./budget_exceeded_errors.md), 422 by default, and the message adds the estimate:

```text
Budget has been exceeded! Team=team-research Current cost: 9.5, Estimated request cost: 1.0, Max budget: 10.0
```

The estimate prices the request's input plus its `max_tokens` or `max_completion_tokens`, capped at the model's output limit. A request that sets neither is estimated at 16,384 output tokens, or the model's output limit when that is lower. Set `max_tokens` on requests from a key that runs close to its cap, so the estimate reflects what the request can really cost.

### Performance

When the counter reads below the cap, the setting adds up to one database read per budget the request falls under. LiteLLM caches each read in the worker for 5 seconds, so the extra load is at most one read per budget per worker every 5 seconds, not one per request. A request that is already over its cap is rejected without the read. Without Redis, every worker relies on these database reads, and while the database is unreachable every budgeted request under its cap returns 503.

## Limits

The proxy-wide `litellm_settings.max_budget`, [per-model budgets](./per_model_budgets.md), and agent session budgets track spend on their own paths, and the setting does not change how they are read.

Some requests are never reserved. Routes the model's pricing cannot estimate, such as some image and audio routes, are checked only against recorded spend. A `POST /batches` request names an input file rather than its prompts, so LiteLLM cannot price the whole batch at submission and records its cost when the batch completes. See [Batch requests](./users.md#batch-requests).

## Related

See [Budget exceeded errors](./budget_exceeded_errors.md) for the error a refused request receives, [Budget reservation](./users.md#budget-reservation) for how reservation estimates cost, and [Budgets and spend limits](./budgets.md) for every scope a request is checked against.

## Related pages

- [Temporary budget increase](https://docs.litellm.ai/docs/proxy/temporary_budget_increase.md)
- [Self-serve budget changes](https://docs.litellm.ai/docs/proxy/self_serve_budgets.md)
