# Rate limits

How many requests a key can make, and what to do when it makes too many.

By default each API key can make **120 requests a minute**, across all routes. The count starts again with every minute of the clock.

A request over the limit isn't carried out. It answers `429` with a `Retry-After` header, in seconds:

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 60

{"message":"API key rate limit exceeded"}
```

Wait that long, then repeat the request:

**Node.js**:

```js
async function chatwise(path, options = {}) {
  for (;;) {
    const response = await fetch(`https://api.chatwise.so${path}`, {
      ...options,
      headers: { ...options.headers, Authorization: `Bearer ${process.env.CHATWISE_API_KEY}` },
    });
    if (response.status !== 429) return response;
    const seconds = Number(response.headers.get("retry-after") ?? 60);
    await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
  }
}
```

**Python**:

```python
import os
import time
import urllib.error
import urllib.request


def chatwise(path):
    request = urllib.request.Request(
        f"https://api.chatwise.so{path}",
        headers={"Authorization": f"Bearer {os.environ['CHATWISE_API_KEY']}"},
    )
    while True:
        try:
            return urllib.request.urlopen(request)
        except urllib.error.HTTPError as error:
            if error.code != 429:
                raise
            time.sleep(int(error.headers.get("Retry-After", 60)))
```

## Stay under it

- Read lists with `limit=100`.
- Use [webhooks](https://chatwise.so/docs/webhooks.md) instead of asking again and again for new messages.
- Give each integration its own key: each key has its own limit.

A request refused because its key is invalid or lacks the route's scope doesn't count. Meta has limits of its own for sending and creating templates.
