> ## Documentation Index
> Fetch the complete documentation index at: https://express-quota-limiter.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quota-Remaining header and HTTP 429 error response format

> Reference for the Quota-Remaining and Quota-Limit headers and the JSON body returned on HTTP 429 when a quota is exceeded in Express.

Every response from a quota-limited route includes HTTP headers that tell the caller how much quota remains and what the configured limit is. The middleware sets these headers on **every** request — whether the request was allowed or blocked — so your clients always have up-to-date quota information without needing to make a separate API call.

## Response headers

| Header | Description |
| - | - |
| `Quota-Remaining` | The number of operations remaining in the current quota window |
| `Quota-Limit` | The configured limit for this quota key |

Both values are strings (as required by the HTTP spec). `Quota-Remaining` is always `>= 0` — it never goes negative, even if a weighted request would have pushed the counter below zero.

### When headers are set

The middleware sets both headers on every request that reaches the quota check, including:

* Requests that are **allowed** — headers reflect the updated remaining value after decrement.
* Requests that are **blocked** — `Quota-Remaining` is `0` and `Quota-Limit` reflects the configured limit.

> [!NOTE]
>
> Headers are **not** set when `keyGenerator` returns an empty string (the quota check is skipped) or when a storage error occurs with `failOpen: true` (the request passes through without a decrement).

***

## HTTP 429 response

When a request is blocked because the quota is exhausted, the middleware responds with `429 Too Many Requests` and a JSON body:

```json theme={null}
{
  "error": "Too Many Requests",
  "message": "Monthly email quota exceeded",
  "quota": { "limit": 500, "remaining": 0 }
}
```

| Field | Description |
| - | - |
| `error` | Always `"Too Many Requests"` |
| `message` | The value of the `errorMessage` option (default: `"Quota exceeded"`) |
| `quota.limit` | The resolved limit for this request |
| `quota.remaining` | Always `0` when quota is exceeded |

You can customize `message` to give callers context about which quota was hit:

```typescript theme={null}
const emailQuota = createQuotaLimiter({
  storage: new RedisDriver(redis),
  limit: 500,
  keyGenerator: (req) => `quota:emails:${req.tenantId}`,
  errorMessage: "Monthly email quota exceeded",
});
```

***

## Storage error behavior

When the storage driver throws and `failOpen` is `true` (the default), the middleware calls `next()` and the request passes through. In this case **neither header is set** because no decrement was performed and no quota value is available to report.

When `failOpen` is `false` and a storage error occurs, the middleware returns HTTP 500 and no quota headers are set:

```json theme={null}
{
  "error": "Internal Server Error",
  "message": "Quota service unavailable"
}
```

> [!WARNING]
>
> If your client code relies on `Quota-Remaining` being present on every response, handle the case where the header is absent — this indicates a storage error occurred with `failOpen: true`.

***

## Using `Quota-Remaining` in client code

The `Quota-Remaining` header lets you build real-time usage dashboards and proactive warnings without any additional API endpoints. Read the header from every response and store the latest value for your UI:

```typescript theme={null}
const response = await fetch("/send-email", { method: "POST", body });

const remaining = response.headers.get("Quota-Remaining");
if (remaining !== null) {
  updateUsageDashboard(parseInt(remaining, 10));
}

if (response.status === 429) {
  const body = await response.json();
  showQuotaExceededError(body.message);
}
```

> [!TIP]
>
> Combine the `Quota-Remaining` header with the `onQuotaChecked` callback to keep a server-side copy of remaining quota in your database. This lets you display accurate quota information even on pages that don't make a quota-limited request.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.