# Errors and retries

> Baker refuses in two ways. A request it cannot read answers a `4xx` with `{ "ok": false, "error": { "code", "message" } }`. A request it can read answers `200`, and each event it refused is listed in `data.rejected`. Retry `429`, `5xx` and timeouts with the same `event_id`s; never retry another `4xx` unchanged.

Source: https://withbaker.com/docs/errors · Updated 2026-11-23

## Request errors and rejected events

- **The request.** Nothing in it was read: the key is wrong, the body is not JSON, a field is unknown, the batch is too big. The status says so, and the body is the error envelope below. Nothing was stored.
- **One event.** The request was read, and one event in it is wrong: an amount of `"1,200"`, a timestamp in the future, nobody named. The answer is a `200`; the event is listed in `data.rejected` with its `index` in your array, and **every other event in the batch still counts**.

The second kind is why a batch is safe to send: a contact with no email, once a week, costs you that one event and tells you which, instead of the whole day's batch.

## The error envelope

```json
{
  "ok": false,
  "error": {
    "code": "invalid_api_key",
    "message": "Missing or invalid Authorization header"
  }
}
```

`error.code` is what to branch on, `error.message` what to log.

| Status | Code | Means | Retry |
| --- | --- | --- | --- |
| `200` | `ok: true` | The request was read. Single events may still be refused: read `data.rejected`. | No |
| `400` | `invalid_request` | The body is not the documented shape, anywhere in the batch: not JSON, an unknown field, a field of the wrong JSON type, an event with no event_name, or an X-Baker-Mode that is neither live nor test. Fix the request. The message names the first field that is wrong by its path, such as events.3.event_name. | No |
| `401` | `invalid_api_key` | The key is missing, mistyped or revoked. Check the Authorization header and the key in Baker. | No |
| `403` | `forbidden` | The key is valid but may not send events, the company's Baker account is closed, or the public test key was asked to go live. Use a key created as Sending events only. The public test key only rehearses. | No |
| `413` | `batch_too_large` | More events, or more bytes, than one request may carry. Split the batch and send each half. | After splitting |
| `429` | `rate_limited` | Over the requests-per-minute budget: the company's, or the public test key's. Wait for the seconds in Retry-After, then send the same request again. | Yes |
| `500` | `internal_error` | A fault on our side. Nothing was written. Retry with exponential backoff, with the same event_ids. | Yes |

On `404 not_found`: only a [source address](https://withbaker.com/docs/authentication.md#source-addresses-for-tools-that-cannot-set-a-header) answers it.

## Rejection codes

| Code | Fix |
| --- | --- |
| `invalid_event_id` | Send an id of 1 to 128 letters, digits and `. _ : -`, or leave `event_id` out. |
| `invalid_name` | Send a name of up to 80 characters that starts with a letter or a digit. |
| `missing_identity` | Add at least one way to name the person in `user_data`: an email, a phone, your own `external_id`, a `baker_id`, a click id, `fbp` or `fbc`. A value that is not one (an email with no `@`) names nobody. |
| `invalid_timestamp` | Send ISO-8601 with an offset (`2026-11-20T14:03:00Z`) or Unix seconds (not milliseconds: `Math.floor(Date.now() / 1000)`), no more than 5 minutes ahead. |
| `invalid_value` | Send `value` as a plain non-negative decimal (`1200.50`, no thousands separator, no exponent) with an uppercase ISO-4217 `currency` (`EUR`, not `eur`). |
| `batch_too_large` | Never in `rejected`: it is the `413` for the whole request. Split it: at most 500 events and 8 MB each. |
| `invalid_items` | Name each line by `product_id`, `variant_id` or `feed_id`; send `quantity` from 1 to 1,000,000 and `price` with a `currency`. |
| `invalid_consent` | Send `granted` or `denied`, or leave the field out. |

> **Note:** Codes are only ever appended. Handle one you do not know as a refusal: log it with its message, and do not retry it.

## Retries, timeouts and idempotency

- **`429`**: wait the seconds in the `Retry-After` header, then send the same request.
- **`5xx`, a timeout or a dropped connection**: retry with exponential backoff and jitter (for example 1, 2, 4, 8 seconds), up to a few minutes. A request that timed out may still have arrived, which is why the retry carries the same `event_id`s. Give each request a client timeout of 10 to 30 seconds.
- **`413`**: split the batch in two and send each half.
- **Any other `4xx`**: do not retry. The same request will be refused the same way. Fix it, or log it for a person.
- **An event in `rejected`**: do not resend it as it is. Fix the event and send it alone.

> **Tip:** Retries are safe when every event carries an `event_id`: the same id sent twice counts once. Without one, a retry of a request that did arrive counts its events twice. See [Deduplication](https://withbaker.com/docs/deduplication.md).

## Log what you send

Log the status, `received`, `accepted` and every entry of `rejected` for each request. Discarding the body of a `200` is the most common way an integration looks right while dropping events. In Baker, **Measure → Events** lists refused events with what was sent, which is the quickest way to see why.

## Need help?

Write to support@withbaker.com: a person answers within 24 hours. The OpenAPI description is at https://withbaker.com/docs/openapi.json.
