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-Remainingis0andQuota-Limitreflects 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 with429 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 andfailOpen 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:
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: