Skip to main content
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

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.
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:
You can customize message to give callers context about which quota was hit:

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