# Rate limits

Each agency owner may send 50 requests per 60 seconds. The limit is shared across all of the
owner's keys, so more keys do not raise it.

When the limit is exceeded, the API returns `429` with a `Retry-After` header (seconds) and
`RateLimit-*` headers that describe the current window.

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 12
Content-Type: application/problem+json
```

## Invalid keys

Requests with an invalid key are limited per IP address: 20 failures per 60 seconds. After that,
requests from that address are answered with `429`, even with a valid key.

## Backoff

Wait for `Retry-After` when it is present, otherwise back off exponentially with jitter.

```ts
async function call(url: string, key: string, tries = 5): Promise<Response> {
  for (let attempt = 0; attempt < tries; attempt++) {
    const res = await fetch(url, { headers: { "X-API-Key": key } });
    if (res.status !== 429 && res.status < 500) return res;
    const wait = Number(res.headers.get("Retry-After"));
    const ms = wait > 0 ? wait * 1000 : Math.min(30_000, 500 * 2 ** attempt) * (0.5 + Math.random() / 2);
    await new Promise((resolve) => setTimeout(resolve, ms));
  }
  throw new Error("Retries exhausted");
}
```

Spread requests evenly instead of sending bursts.
