# Errors

> The error response shape, every status and error code the public API returns, and whether the Luau SDK retries or drops each one.

When a request fails, the API answers with a non-2xx status and a JSON body in one shape:

```json
{
  "error": {
    "code": "invalid_batch",
    "message": "Rejected batch: protocol Invalid input: expected 1",
    "details": {}
  }
}
```

| Field | Type | Meaning |
| --- | --- | --- |
| `error.code` | string | A stable, machine-readable code. Branch on this and on the status. |
| `error.message` | string | A human-readable explanation. Log it, show it to a developer, but don't parse it: wording can change. |
| `error.details` | object | Optional. Present on some `400` responses, for example a `fields` map from field name to problem. |

The only response that doesn't follow this shape is a request to a path that doesn't exist (see [`404`](#404-not-found)).

## Status codes at a glance

| Status | Meaning | Retry? |
| --- | --- | --- |
| `200`, `202`, `204` | Success | — |
| `400` | The request is malformed or fails validation | No. Fix the request. |
| `401` | Missing or wrong project ID or key, or a failed bridge replay check | No, except `stale_request` after fixing the clock |
| `404` | Unknown path, file, share link or widget | No |
| `413` | Body too large | No. Send smaller batches. |
| `415` | Unsupported `Content-Type` | No. Send `application/json`. |
| `429` | Rate limited | Yes, with backoff |
| `500` | Unexpected error on Bloxlytics' side | Yes, with backoff |
| Other `5xx` | Bloxlytics is temporarily unreachable | Yes, with backoff |

## Every error code

### 400 Bad Request

| Code | Returned by | Message and cause |
| --- | --- | --- |
| `invalid_batch` | `POST /v1/ingest` | `Rejected batch: <path> <problem>` — the envelope (`protocol`, `sdk`, `server` or the `events` array itself) is invalid, or **every** event in the batch is invalid. When events are the problem, the path names the first bad one, for example `Rejected batch: events.0.id (PetHatched) Too small: expected string to have >=8 characters`. If only some events are invalid, the batch is accepted instead; see [partial rejection](https://docs.bloxlytics.app/api/ingest/send-events#partial-rejection). |
| `invalid_payload` | `POST /v1/bridge/*` | `<path>: <problem>` — the body doesn't match the endpoint's schema, for example `protocol: Invalid input: expected 1` or `players.0: Too small: expected number to be >0`. |
| `bad_request` | `GET /api/public/dashboards/:token/widgets/:widgetId` | `Some fields need attention.` — a query parameter is invalid. `details.fields` maps each parameter to its problem, for example `{ "fields": { "range": "Invalid option: …" } }`. |
| `bad_request` | Any | `Invalid request.` — a value failed a validation step that has no more specific code. |
| `FST_ERR_CTP_INVALID_JSON_BODY` | Any `POST` | `Body is not valid JSON but content-type is set to 'application/json'` |
| `FST_ERR_CTP_EMPTY_JSON_BODY` | Any `POST` | `Body cannot be empty when content-type is set to 'application/json'` |

The validation messages after the path (`Too small: …`, `Invalid input: …`) are descriptive text, not codes. Rely on `error.code`.

### 401 Unauthorized

| Code | Returned by | Message and cause |
| --- | --- | --- |
| `unauthorized` | `/v1/*` | `Missing project id or key.` — no `X-Bloxlytics-Project` header, a value that isn't a Universe ID or known legacy project ID, or no `Authorization: Bearer …` header. |
| `unauthorized` | `/v1/*` | `Invalid project key.` — the key isn't this project's current key of the right kind: wrong or rotated key, write key on a bridge endpoint (or the reverse), or the project no longer exists. |
| `stale_request` | `/v1/bridge/*` | `Request timestamp is outside the allowed window.` — `X-Bloxlytics-Timestamp` is missing or more than 120 seconds from Bloxlytics' clock. |
| `bad_nonce` | `/v1/bridge/*` | `Missing nonce.` — `X-Bloxlytics-Nonce` is missing or isn't 16–64 characters of `A–Z a–z 0–9 - { }`. |
| `replayed` | `/v1/bridge/*` | `Nonce already used.` — this nonce was already used for this project in the last 250 seconds. |

See [Authentication](https://docs.bloxlytics.app/api/authentication) for how each header is checked.

### 404 Not Found

| Code | Returned by | Message |
| --- | --- | --- |
| `not_found` | `GET /api/sdk/:file` | `Unknown SDK file.` |
| `not_found` | `GET /api/public/dashboards/:token…` | `This link doesn't exist or has been revoked.` — the token is malformed, unknown or revoked, or the dashboard is no longer shared with the project. |
| `not_found` | `GET /api/public/dashboards/:token…` | `This link has expired. Ask the person who shared it for a new one.` |
| `not_found` | `GET /api/public/dashboards/:token/widgets/:widgetId` | `Widget not found.` — the widget isn't on that dashboard (it may have been removed). |

A path the API doesn't serve at all, such as a misspelt path or a `GET` to a `POST` endpoint, returns a different body:

```json
{ "message": "Route GET:/v1/bridge/poll not found", "error": "Not Found", "statusCode": 404 }
```

On `api.bloxlytics.app`, paths outside `/v1/`, `/api/sdk/` and `/api/health` are answered with `404` before they reach the API, so the body isn't JSON.

### 413 Payload Too Large

| Code | Message |
| --- | --- |
| `FST_ERR_CTP_BODY_TOO_LARGE` | `Request body is too large` |

The limit is 1 MB for `POST /v1/ingest` and 2 MB for every other endpoint. The body is measured before anything else is checked, so an oversized request gets `413` even with a bad key.

### 415 Unsupported Media Type

| Code | Message |
| --- | --- |
| `FST_ERR_CTP_INVALID_MEDIA_TYPE` | `Unsupported Media Type` |

Send `Content-Type: application/json`. A `text/plain` body isn't refused here, but it's read as a string and then fails validation with `400`.

### 429 Too Many Requests

| Code | Returned by | Message |
| --- | --- | --- |
| `rate_limited` | `/v1/*` (per-project limits) | `Too many requests.` |
| `bad_request` | Per-IP limits on `/api/sdk/:file` and `/api/public/dashboards/*` | `Bad request.` |

> **Note:** Responses from the per-IP limits currently carry the code `bad_request` instead of `rate_limited`. Treat any `429` status as a rate limit whatever the code says. These responses include a `Retry-After` header (seconds); the per-project `429` doesn't, and its window resets at the start of the next minute.

Limits are listed in the [introduction](https://docs.bloxlytics.app/api#rate-limits).

### 500 Internal Server Error

| Code | Message |
| --- | --- |
| `internal` | `Something went wrong on our side. Try again.` |

Nothing about your request is wrong. Retry with backoff. For ingest, retrying is safe because events are deduplicated by `id`.

## What the SDK does

The Luau SDK handles every error for you and never stops your game because of one.

### Analytics (ingest)

| Result of `POST /v1/ingest` | What the SDK does |
| --- | --- |
| Any `2xx` | Removes the batch from its queue. |
| No response (network error or timeout), `429`, or any `5xx` | Keeps the batch and waits before trying again: 2 seconds, then 4, 8, 16, 32, and 60 seconds at most. A success resets the wait. The retry sends the same event ids, so nothing is counted twice. |
| Any other `4xx` (`400`, `401`, `404`, `413`, `415`) | Drops the batch, because sending it again can't succeed, and prints one warning per status code: `[Bloxlytics] API rejected a batch (401): …` |

While the API is unreachable the server keeps queuing, up to 5,000 events. After that it drops the oldest events first and warns once. On shutdown the SDK keeps flushing for up to 20 seconds. See [Delivery](https://docs.bloxlytics.app/sdk/delivery).

| Result of `GET /v1/config` | What the SDK does |
| --- | --- |
| `200` | Applies the new settings. |
| Anything else | Keeps the settings it already has (its defaults, if it has never loaded any) and tries again at the next refresh, 300 seconds later. |

### Cmdr bridge

| Request | On failure |
| --- | --- |
| `POST /v1/bridge/hello` | Warns `[Bloxlytics bridge] registration failed (<status>): <message>`, then retries after 5 seconds, doubling up to 120 seconds, until it succeeds. Commands don't run until it does. |
| `POST /v1/bridge/poll` | Waits 2 seconds, doubling up to 60 seconds, then polls again. A `204` counts as an empty poll, not a failure. |
| `POST /v1/bridge/result` | Not retried. If no result arrives, the command is marked as timed out (`The game server didn't respond in time.`), at the latest two minutes after it was delivered. A result that arrives after that is ignored. |
| `POST /v1/bridge/bye` | Not retried; the server is shutting down. Without it, Bloxlytics stops counting the server as online 90 seconds after it was last heard from. |

Every bridge retry gets a fresh timestamp and nonce, so retries never fail as `replayed`.

### Finding the cause

If the API rejects requests, the project's **SDK** page shows it under **Debugger**: counts of accepted and rejected events and batches, and **Recent problems**, the last 50 rejection messages (cleared 7 days after the most recent one). The messages are the same text as the `invalid_batch` messages above, plus the reasons events were rejected after the batch was accepted. Requests that fail authentication (`401`) or arrive too large (`413`) aren't recorded there; look for the SDK's warning in the server output instead. See [Troubleshooting](https://docs.bloxlytics.app/help/troubleshooting).
