# Rate limits

By default an account has 1 API key(s); each key allows 1 concurrent WebSocket connection(s) and 1 REST/MCP request every 3 seconds.

> Source: https://tokenearly.com/en/developers/limits · Docs index: https://tokenearly.com/en/developers/llms.txt · OpenAPI: https://api.tokenearly.com/v1/openapi.json

## At a glance

| Item | Limit | When exceeded |
|---|---|---|
| API keys | 1 per account | Cannot create another; revoke one first |
| WebSocket connections | 1 at a time per key | The new connection is refused with close code `4029` |
| REST and MCP | 1 request every 3 seconds per key (combined) | `429`; wait `Retry-After` seconds |
| History window | Set by your plan; see `limits.api_history_days` in `/v1/me` | Older events are simply not returned (no error) |

Endpoints that need no key (`/v1/topics`, `/v1/schema`, `/v1/health`) are not rate limited.

> The table shows defaults. Limits can be adjusted per account or per key (for example a higher rate or more connections for one key); call `GET /v1/me` and read `limits` for what applies to your key.

When a limit changes (the defaults, your account or one of your keys), open streams immediately receive an `op = "notice"` message with the old and new values. The same records are available from [GET /v1/notices](https://tokenearly.com/en/developers/rest/notices) and in the dashboard change log.

## REST rate limit

Two requests with the same key must be at least 3 seconds apart. Successful (200) responses from endpoints that need a key carry the headers below; a `429` carries them too, plus `Retry-After`; other error responses carry none of them:

| Header | Meaning |
|---|---|
| `X-RateLimit-Limit` | Requests allowed per window (1) |
| `X-RateLimit-Window` | Window length in seconds (3) |
| `X-RateLimit-Remaining` | Requests left in the current window |
| `X-RateLimit-Reset` | Seconds until the next request is allowed |
| `Retry-After` | Only on 429: whole seconds to wait before retrying |

### Which requests count

| Request | Counts? |
|---|---|
| Successful requests (200) | Yes |
| Requests that fail after authentication: `400 invalid_cursor`, `404 not_found` from `GET /v1/events/{id}` | Yes (the response has no rate-limit headers) |
| Failed authentication: `401` (missing, invalid or expired key), `403` (`ip_not_allowed`, `plan_required`) | No |
| Malformed parameters, `400 invalid_parameter` (e.g. `limit` out of range; rejected before the key is checked) | No |
| Unknown path (`404`) or wrong method (`405`) | No |
| Requests refused with `429` | No, and they do not push back the next allowed time |
| `/v1/topics` (with or without a key), `/v1/schema`, `/v1/health` | No |
| MCP `get_events`, `get_event`, `get_alerts`, `whoami` (as do REST `/v1/events`, `/v1/alerts`, `/v1/me`, `/v1/notices`) | Yes, from the same allowance as REST; MCP responses are JSON-RPC and carry none of these headers. Over the limit the tool returns a `rate_limited` error whose message says how many seconds to wait |
| MCP `list_topics`, `get_schema`, `initialize` and `tools/list` | No |

**Retry with Retry-After**

```python
import time, requests

def get(url, key, tries=5):
    for i in range(tries):
        r = requests.get(url, headers={"Authorization": f"Bearer {key}"}, timeout=10)
        if r.status_code != 429:
            r.raise_for_status()
            return r.json()
        time.sleep(int(r.headers.get("Retry-After", "1")))   # wait as instructed
    raise RuntimeError("still rate limited")
```

> REST is for history and catching up, not for polling new items. For real-time data connect to the WebSocket: new announcements are pushed to you and the stream does not count against the REST limit.

## WebSocket connections

Connections are counted per key: each key may hold up to 1 stream connection(s). When its allowance is full a new connection receives `too_many_connections` and is closed with code 4029; close the old one first. Need more connections (say one per server)? Create more keys and give each server its own. Connections that drop without a clean close are released automatically once heartbeats time out, usually within a minute.

If a client falls more than 500 events behind it is closed with 4008; reconnect with `after` to resume.
