# Rate limits

All your secret keys together get 600 requests a minute. The public key has two limits: 60 requests a minute from one IP address and 600 a minute from all addresses together. Bot and website requests are counted separately.

## What to do after 429

1. Read `Retry-After` in the response and send no requests for that many seconds.
2. Repeat the request. If you get `429` again, make the pause longer.
3. Request less often: cache responses, use a larger `limit` to get more records per request, and don't poll more often than the data changes.

A new key will not raise the limit: secret keys share it. A page with the public key runs out of the limit if it requests data too often: refresh it no more than once every 30 seconds.

## How to check what is left

A response to a request with a valid key has two headers:

```
RateLimit-Policy: "app-user";q=600;w=60, "app";q=6000;w=60, "user";q=1200;w=60
RateLimit: "app-user";r=599;t=42, "app";r=5999;t=42, "user";r=1199;t=42
```

`q` is the limit per window, `w` is the window length in seconds, `r` is how many requests are left, `t` is how many seconds until the window starts again. In a `429` response, the `Retry-After` header says how many seconds to wait before repeating the request, and the `policy` field says which limit ran out:

| Name (`policy`) | What it limits | Per minute |
|---|---|---|
| `app-user` | all your secret keys together; separately, the public key from all addresses | 600 |
| `publishable-ip` | the public key from one IP address | 60 |

The headers also list `user` (1200) and `app` (6000): for your keys they never run out before `app-user`.

Responses without a valid key (401, `wrong_token_type`, `token_in_query`, `origin_not_allowed`) don't have these headers.

Error: [rate_limited](https://developers.donatty.com/en/errors/rate_limited.md).
