> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Limits, close codes and errors

> Connection limits on /v1/ws, the close codes the server uses, and every error code a subscription can return.

## Limits

These are the current defaults. They may change, so don't hard-code them where you can avoid it.

| Limit | Default | What happens when exceeded |
| - | - | - |
| Size of one message you send | 64 KiB (65,536 bytes) | Connection closed with code `1009` |
| Messages you send per second | 20, counted in fixed 1-second windows | Connection closed with code `4029`, reason `Too many messages` |
| Subscription weight per connection | 100 | The subscribe fails with `SUBSCRIPTION_LIMIT`. The connection stays open. |
| Unsent data queued for your connection | 4 MiB | Connection closed with code `4008`, reason `Too slow, reconnect and resume from your cursor` |
| Heartbeat | Protocol ping every 30 s | No pong before the next ping: connection dropped, you see `1006` |
| Items in `tokens` / `pools` | 1 to 100 per subscription | `INVALID_PARAMETERS` |
| `maxUpdatesPerMinute` | 1 to 600 | `INVALID_PARAMETERS` |
| Resume history | About 10 minutes of blocks per chain | `RESUME_EXPIRED` |
| Cursor checkpoint interval | About 30 s | Not a limit. See [Checkpoints](https://sonar-cf3aeac7.mintlify.site/websocket/cursors-and-resume.md#checkpoints). |

**What counts as a message:** every frame you send counts toward the 20-per-second limit, including `{"op":"ping"}`, `unsubscribe` and frames the server rejects as invalid. When you resubscribe after a reconnect, pace your subscribe messages.

### Subscription weight

Each subscription costs as many slots as the number of things it follows. The total across one connection must stay at or below 100.

| Channel | Weight |
| - | - |
| `fast-trade` | 1 |
| `ohlcv` | 1 |
| `token-details` | Number of distinct addresses in `tokens` |
| `market-details` | Number of distinct addresses in `pools` |

For example, one `token-details` subscription with 60 tokens plus 40 `fast-trade` subscriptions uses the full 100. Duplicate addresses in a list are removed and count once. The 100-item list maximum is checked before duplicates are removed.

```json theme={null}
<- {"type":"error","id":"watchlist-2","code":"SUBSCRIPTION_LIMIT","message":"At most 100 subscriptions, each entry in a list counts as one"}
```

If you need more, open another connection.

### Connection rejected at upgrade

These are plain HTTP responses to the WebSocket handshake. No WebSocket frames are sent.

| HTTP status | Cause | What to do |
| - | - | - |
| `404 Not Found` | The path is not `/v1/ws` (or another ChainQuery WebSocket path) | Check the URL. |
| `503 Service Unavailable` | The server is restarting, or the instance you reached is at its connection capacity | Retry with backoff. |

## Close codes

| Code | Reason text | Cause | Recommended reaction |
| - | - | - | - |
| `1006` | (none, no close frame) | You did not answer a protocol ping in time, or the network dropped. | Make sure your client answers pings. Reconnect with backoff and resume with `since`. |
| `1009` | Set by the server library | A message you sent was larger than 64 KiB | Fix the client. Split large `tokens` or `pools` lists across subscriptions. Reconnecting with the same message fails again. |
| `1012` | `Server restarting, reconnect and resume` | Planned restart. A [`reconnect`](https://sonar-cf3aeac7.mintlify.site/websocket/messages#reconnect) message is sent first. | Reconnect right away, with a little jitter, and resume with `since`. |
| `4008` | `Too slow, reconnect and resume from your cursor` | Your client is not reading fast enough and more than 4 MiB of messages queued up | Reconnect and resume with `since`. Process messages faster, move slow work off the receive loop, or subscribe to less. Consider `maxUpdatesPerMinute` for display-only data. |
| `4029` | `Too many messages` | More than 20 messages in one second | Reconnect with a longer backoff, and pace your messages. |

The protocol also defines `1000` (normal) and `1008` (policy violation). The server does not currently send them.

### Planned restarts

When a server instance shuts down:

1. Every connection receives `{"type":"reconnect"}`.
2. Connections are then closed with `1012` one by one, spread over about 20 seconds.
3. New connection attempts to that instance get HTTP `503` during this time.

Your subscriptions are removed when the connection closes. Open a new connection and resubscribe with your stored cursors. See the [reconnect loop](https://sonar-cf3aeac7.mintlify.site/websocket/cursors-and-resume.md#reconnect-loop).

## Error codes

Errors are sent as `error` messages and never close the connection. The `id` field tells you which subscription failed. Errors about the message envelope itself have no `id`.

```json theme={null}
{"type":"error","id":"my-sub","code":"INVALID_PARAMETERS","message":"maxUpdatesPerMinute: Too big: expected number to be <=600","details":[{"field":"maxUpdatesPerMinute","message":"Too big: expected number to be <=600"}]}
```

Every error code that `/v1/ws` can send today:

| Code | `id` | Message | Trigger |
| - | - | - | - |
| `BAD_REQUEST` | No | `Messages must be JSON text` | A binary frame, or text that is not valid JSON |
| `INVALID_PARAMETERS` | No | One `field: message` entry per problem; `details` lists them | The message is valid JSON but not a valid `subscribe`, `unsubscribe` or `ping`. For example: unknown `op`, missing or malformed `id`, missing `params`, or malformed `since`. |
| `UNKNOWN_CHANNEL` | Yes | `Unknown channel: <name>` | `channel` is not `fast-trade`, `token-details`, `market-details` or `ohlcv` |
| `DUPLICATE_SUBSCRIPTION` | Yes | `Subscription <id> already exists` | The `id` is already used by an active subscription, or by one that is still being set up |
| `INVALID_PARAMETERS` | Yes | One `field: message` entry per problem; `details` lists them | `params` failed the channel's validation, for example a missing `chain`, a chain not in `evm:<n>` form, or neither `token` nor `pool` |
| `INVALID_ADDRESS` | Yes | Same format | `params` failed validation and **every** problem is a malformed address |
| `INVALID_PARAMETERS` | Yes | `A sampled subscription drops items and cannot resume, subscribe without since or maxUpdatesPerMinute` | `since` sent together with `maxUpdatesPerMinute` |
| `INVALID_PARAMETERS` | Yes | `Unknown pairs in since`; `details.pairs` lists them | A `since` map names a pair other than `<channel>\|<chain>` |
| `SUBSCRIPTION_LIMIT` | Yes | `At most 100 subscriptions, each entry in a list counts as one` | The subscription would push the connection's total weight over 100 |
| `TOKEN_NOT_FOUND` | Yes | `Token or pool not found` | `ohlcv` only: `token` without `pool`, and no pool was found for the token |
| `TOKEN_NOT_FOUND` | Yes | `Token is not in this pool` | `ohlcv` only: `token` and `pool` given, and the token is not one of the pool's two tokens |
| `POOL_NOT_FOUND` | Yes | `Pool not found` | `ohlcv` only: the `pool` is not known |
| `RESUME_EXPIRED` | Yes | `Cursor is older than the stream history`; `details.retainedFrom` is the oldest retained block | `since` points before the retained history |
| `INTERNAL_ERROR` | Yes | `Subscription failed, try again` | Unexpected server failure while setting up the subscription |
| `NOT_FOUND` | Yes | `Unknown subscription <id>` | `unsubscribe` with an `id` that is not active |

Notes:

* Address validation messages are `must be a valid token or wallet address` for `token` and `tokens`, and `must be a valid token address or pool id` for `pool` and `pools`.
* Other validation wording, such as for missing fields or out-of-range numbers, comes from the schema library and may change. Match on `code` and `details[].field`, not on message text.
* Only `ohlcv` checks that a token or pool exists. The other channels accept any well-formed address, and an address that never trades simply produces no events.
* After any subscribe error except `DUPLICATE_SUBSCRIPTION`, the `id` is free and you can retry with it.

### Recommended reactions

| Code | Reaction |
| - | - |
| `BAD_REQUEST`, envelope `INVALID_PARAMETERS` | Client bug. Validate `id` (1–64 chars, `^[\w.:-]+$`) and `since` before sending. |
| `INVALID_PARAMETERS`, `INVALID_ADDRESS` | Fix the params. Don't retry unchanged. |
| `UNKNOWN_CHANNEL` | Fix the channel name. |
| `DUPLICATE_SUBSCRIPTION` | Use a different `id`, or `unsubscribe` first. |
| `SUBSCRIPTION_LIMIT` | Unsubscribe from something, or open another connection. |
| `TOKEN_NOT_FOUND`, `POOL_NOT_FOUND` | Check the address and chain. For a new token, retry later once it has a pool. |
| `RESUME_EXPIRED` | Subscribe without `since`, then backfill from REST. See [History retention](https://sonar-cf3aeac7.mintlify.site/websocket/cursors-and-resume.md#history-retention). |
| `INTERNAL_ERROR` | Retry the subscribe after a short delay. |
| `NOT_FOUND` | The subscription is already gone. Nothing to do. |

The protocol's error code list also includes `ASSET_NOT_FOUND`, `UNAUTHORIZED`, `FORBIDDEN`, `RATE_LIMITED` and `SERVICE_UNAVAILABLE`, shared with the [REST API](https://sonar-cf3aeac7.mintlify.site/concepts/responses-and-errors.md). `/v1/ws` does not send them today. Rate limiting on WebSockets is enforced with close code `4029`, not with an error message.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.