Docs / Rate limits and quotas
Rate limits and quotas
One quota per database key per UTC month, plus an optional per-minute request limiter. Both answer 429; they are told apart by the body and the headers.
429 is two different things
The monthly billable-item quota and the optional per-minute request limiter both answer 429, with different bodies and different headers. Read detail.error: quota_exceeded or rate_limited.
Header names in this contract
| Header | Value seen in the contract |
|---|---|
content-type | application/json |
retry-after | 2254140 |
x-ratelimit-limit | 60 |
x-ratelimit-remaining | 0 |
x-ratelimit-reset | 2026-11-05T12:01:00.000000Z |
x-ratelimit-window | 60 |
Extracted from the response and request examples in docs/API.md §4 on every build.
The quota rule, the bodies and the guidance
Source: docs/API.md §4.
4.1 The quota rule
A database key is billed per distinct item received in a UTC month. Re-polling the same snapshot does not bill the same item twice, and a 304 bills no items (it still counts as one request in /v1/usage). The quota check is:
if used > quota: 429It is > and not >= on purpose: an item is billed when it is served, so refusing the request that would serve the quota's last item would make a metered contract unusable.
Measured on this build: a key with quota=1 made one /v1/items?limit=2 call (200, 2 items served); the next metered call returned 429.
4.2 429 body and headers (verified)
HTTP/1.1 429 Too Many Requests
retry-after: 2254140
cache-control: no-store
content-type: application/json{"detail":{"error":"quota_exceeded","detail":"monthly billable-item quota exhausted","quota":1,"used":2,"resets_at":"2026-12-01T00:00:00.000000Z"}}Retry-After is seconds until the first instant of the next UTC month (at least 1).
Ordering. Authentication, then the per-key request limiter (§4.3, when enabled), then the quota check all run inside the authentication dependency — i.e. before query-parameter validation and before conditional-request evaluation. An exhausted key receives 429 for every metered route, including requests that would otherwise be 400 for a bad limit and including a poll that would have been answered 304. Do not treat a 429 where you expected a 400 as a second bug; check the quota (and the request limiter) first. A 401 is decided before either 429, so a bad bearer never spends the key's request window.
4.3 Per-key request limiter (off by default)
A fixed 60 s request limiter is wired into the authentication dependency, but it is off unless the operator sets NEWS_RATE_LIMIT_PER_MINUTE to a positive integer (the default 0, and any unreadable/negative value, leaves it disabled). It applies to database-issued keys only; legacy NEWS_API_KEYS bearers and dev mode are never limited, because they have no customer identity to meter. The counter is one SQLite row per key per window, incremented under BEGIN IMMEDIATE, so the limit is shared across uvicorn workers rather than multiplied by them.
When enabled and the key has spent its window, the request is refused before the handler runs (before query validation, before the quota check, before any item is metered). The refusal is a second 429 shape, distinct from the monthly quota:
HTTP/1.1 429 Too Many Requests
retry-after: 42
cache-control: no-store
x-ratelimit-limit: 60
x-ratelimit-remaining: 0
x-ratelimit-window: 60
x-ratelimit-reset: 2026-11-05T12:01:00.000000Z
content-type: application/json{"detail":{"error":"rate_limited","detail":"too many requests for this api key","limit":60,
"window_seconds":60,"retry_after":42,"resets_at":"2026-11-05T12:01:00.000000Z"}}Retry-After is seconds until the window resets and is always at least 1. An auth failure (401) is evaluated before the limiter, so junk requests cannot spend a real key's window. Item metering is unchanged: a 304 is zero billable items, and a 4xx/5xx is not metered at all.
4.4 Rate-limit headers on allowed responses
The headers below describe the per-key request budget of §4.3 only. They exist so a client can pace itself instead of discovering its budget by being refused.
Two spellings, one verdict. The standard fields from draft-ietf-httpapi-ratelimit-headers-11 (the IETF HTTPAPI Working Group draft, May 2026 — datatracker entry doc/draft-ietf-httpapi-ratelimit-headers) are sent first; the X-RateLimit-* names this API has published since 2026-11-05 are sent alongside them from the same dict, so the two can never quote different numbers. Both are produced by backend/app/api/rate_limit.py::rate_limit_headers.
| Header | Unit | Meaning |
|---|---|---|
RateLimit-Policy | RFC 8941 List | The policy: "perkey";q=<limit>;w=<window>. q is the quota in requests (the draft's default quota unit), w the fixed window in seconds. Describes the policy, not the count, so it is stable between responses. |
RateLimit | RFC 8941 List | The service limit: "perkey";r=<remaining>;t=<seconds>. r is the quota left after this request; t is the draft's effective window — seconds from this response until the count returns. r=0 means the next request in this window is refused. |
X-RateLimit-Limit | requests | Legacy spelling of q. |
X-RateLimit-Remaining | requests | Legacy spelling of r. |
X-RateLimit-Window | seconds | Length of the fixed window, 60. Constant; sent so a client never hard-codes it. |
X-RateLimit-Reset | RFC3339 UTC instant | When the current window ends (e.g. 2026-11-05T12:01:00.000000Z). Absent if the limiter has no reset instant to report. |
Worked example — the first request of a 60-requests-per-minute window, 10 s in:
RateLimit-Policy: "perkey";q=60;w=60
RateLimit: "perkey";r=59;t=50
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
X-RateLimit-Window: 60
X-RateLimit-Reset: 2026-11-05T12:01:00.000000ZWhy t and not an absolute instant: the draft (§4.1.2) defines t as a delay in seconds so a client with a skewed clock is never told to wait past the reset; X-RateLimit-Reset keeps the absolute instant for clients that prefer it. On a refusal, t carries the same number as Retry-After — a client given r=0;t=17 and Retry-After: 42 would be right to distrust both. The draft also says Retry-After takes precedence when both are present (§7), so an existing RFC 9110 client keeps working unchanged.
They appear on allowed responses as well as on the limiter's 429 — a 200, a 206, a 304, and a 400 for a bad query parameter, because every one of those spent a request. They are attached by backend/app/api/rate_headers.py, which copies them from the same helper the refusal uses, so an allowed response and a refusal can never quote different numbers. A response served from the read cache carries the count for that request, never the count stored with the cached bytes.
They are not sent when there is nothing to meter or nothing to say:
- the limiter is disabled (
NEWS_RATE_LIMIT_PER_MINUTEunset or0), or - the caller is anonymous (dev mode) or presents a legacy
NEWS_API_KEYSbearer, which has no customer identity.
A 429 with "error": "quota_exceeded" (§4.2) also carries them: the request limiter allowed that request before the monthly quota refused it, so the window was spent. That refusal's Retry-After is the wait to the next UTC month, not t — the rate-limit fields keep describing the 60 s window they always describe.
The public mirror /v1/site/* publishes the same six headers from its own per-IP limiter (§5a), so a browser rendering the reader site can pace itself the same way a server-side customer does.
These are not the monthly quota. The billable allowance a plan is priced on is counted in unique items delivered per UTC month (§4.1) and is reported by GET /v1/usage (billable_items, quota, remaining, resets_at). RateLimit: "perkey";r=3;t=48 means "three more requests in the next 48 seconds"; it says nothing about how many items remain in the month. Do not build an item budget out of these numbers. No X-Quota-* header exists on this build: the monthly figures live only in the /v1/usage body.
Browser clients. Both CORS layers now expose every one of these names: app/api/cors.py publishes expose_headers containing RateLimit, RateLimit-Policy, the four X-RateLimit-* names and Retry-After (see §5b for the exact value). Before 2026-11-12 the credentialed layer listed only ETag, Last-Modified, Cache-Control, Retry-After, so a browser received X-RateLimit-* and its JavaScript could not read them; backend/tests/test_rate_headers_standard.py::test_both_cors_layers_expose_every_rate_limit_header now fails if either list falls behind the producer.
The document side matches the wire: every metered operation declares these headers on its 200/304/400 and on its 429, so a generated SDK binds a typed accessor instead of discovering the numbers by hand.
Guidance that follows from the cache headers and the pipeline schedule:
- Poll
/v1/feed/{locale}withIf-None-Matchat most once per 60 s per locale. The pipeline runs on a scheduled interval (default 900 s,NEWS_INTERVAL_SECONDS), so a faster poll usually returns a304and only burns a request. - Poll
/v1/metaat most once per 3600 s; it changes only on a deploy or a policy edit. - Page
/v1/itemswithlimit=200when backfilling history. - Back off on
5xxand on network errors: 1 s, doubling, 60 s cap. - Never call
POST /v1/refresh. It needs the operator'sX-Admin-Token(401without it), is not yours to schedule, and answers409if a run is already in progress.
4.5 Request correlation: X-Request-Id
Every response carries an X-Request-Id. It is the one value to quote in a support ticket: it appears on our access log line for that request, so one id joins your report to the hop that served it.
HTTP/1.1 304 Not Modified
x-request-id: 6f1d0a2c4b8e4d5f9a3c7e2b1d0f4a6c
etag: "9b2f0c1d4e6a8b0c2d4e6f8a0b2c4d6e"Rules (implemented in backend/app/api/request_id.py, pinned by backend/tests/test_request_id.py and backend/tests/test_request_id_mount.py; the module is mounted by one line in create_production_app):
- You may send one. We honour an inbound
X-Request-Idonly when it is 1..64 characters of[A-Za-z0-9._:-]. That is the whole accepted shape; a UUID hex is the natural choice. - Anything else is replaced, never reflected. Longer, non-ASCII, or control-character values (newline, NUL) are dropped and we mint a fresh id instead. Do not rely on an id you sent if it is outside that shape.
- We echo OURS when we replace yours. The response header is always authoritative: log the value from the response, not the one you believed you sent.
- It is present on every status —
200,304(the bodyless conditional GET you will poll most),401,404,429and5xx— and on streamed and image (FileResponse) bodies. It is never inside a response body. - It is not a validator and it does not participate in caching: two requests answered from the same cached representation receive different ids, and
ETag/Vary/Content-Lengthare unaffected.
Cross-origin browser code cannot read it until X-Request-Id is added to the CORS expose_headers (and to allow_headers if the browser also sends one); the current list is the one printed in §5. Server-side clients are unaffected.