> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apexiumbet.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket close codes - Why a connection closed and what to do

> Every close code of the Apexium API WebSocket, the refusals at connection time, and what your client should do for each.

Before it closes a connection, the server sends a frame that names the reason: an `error` frame, or a `reconnect` frame before a restart.

```json theme={null}
{ "type": "error", "error": "limit_exceeded", "message": "Fixture limit reached: 500 per account across its connections", "connectionId": "3d9a7f52-…" }
```

The same value is the close reason. Like every `error` frame, it carries the [`connectionId`](https://docs.apexiumbet.com/websocket/overview#log-in) of the connection.

| Code | Reason | Meaning | What to do |
| - | - | - | - |
| `4001` | `bad_login`, `login_failed`, `login_timeout` | The login frame was invalid, the key was refused, or no login came within 10 seconds | Fix the login. Do not retry a refused key in a loop: see [Failed logins](#failed-logins) |
| `4002` | `backpressure` | The connection read too slowly | Reconnect, reload the feed channels, and read faster. See [4002](#4002) |
| `4003` | `access_revoked` | The key, the API access or the account is no longer active | Do not reconnect with this key |
| `4004` | `limit_exceeded` | Too many connections for the key, fixtures for the account, or betslip selections for the connection | Follow fewer fixtures or close other connections, then reconnect. See [4004](#4004) |
| `1011` | `internal_error` | The server failed to handle a frame | Reconnect with backoff |
| `1012` | `server_restart` | The server is restarting; a `reconnect` frame came first | Reconnect at once |
| `1013` | `public_api_disabled` | The API is turned off for maintenance or an incident | Reconnect with backoff; check the [status page](https://apexiumbet.instatus.com) |

A code without a frame, such as `1006`, means the connection was cut: reconnect with backoff.

### 4002

Apexium closes a connection whose send buffer passes 4 MB, or stays not empty for more than 5 seconds. The other clients keep receiving.

Your client may see `1006` instead of `4002`: the close frame waits behind the full buffer, and the connection is cut before it arrives. Treat a `1006` that follows a burst of traffic as a `4002`.

After either, reload the feed channels from `/v1/{lang}`: some changes were not delivered. See [Feed channels](https://docs.apexiumbet.com/websocket/feed-channels.md#read-too-slowly-get-closed) for how to keep up.

### 4004

| Limit | Value |
| - | - |
| Connections per API key | 8 |
| Fixtures per account, summed over its connections | 500 |
| Betslip selections per account, summed over its connections | 50 |

The fixture limit counts `fixtureIds` only; `sportIds` and `tournamentIds` do not count. It applies at login and on every `subscribe` that adds fixtures. A refused `subscribe` keeps nothing of the new selection.

## Refused at connection time

Some refusals come before the WebSocket opens, as an HTTP response to the upgrade:

| Status | `code` | Meaning | What to do |
| - | - | - | - |
| `429` | `RATE_LIMITED` | Too many failed logins from your address | Wait for the `Retry-After` seconds |
| `503` | `PUBLIC_API_DISABLED` | The API is turned off | Retry with backoff |

### Failed logins

Failed logins count with failed REST authentications: after 20 within one minute from the same address, connections from that address are refused until the minute ends. See [Limits](https://docs.apexiumbet.com/api-reference/limits.md#failed-authentication).


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