# Errors and retries

Every error has the same shape, and its `code` never changes. Handle errors by `code`, never by the message text.

```json
{
    "error": {
        "code": "outside_window",
        "message": "The customer has not written to you in the last 24 hours, and WhatsApp lets free text through only as a reply. Send an approved template.",
        "message_id": "0199c5e2-7b3a-7c51-9f0e-3a1d2b4c5e6f",
        "request_id": "req_01k75q3x8f2m9c4v6b7n1d0e5a"
    }
}
```

## What to do

| Situation | Codes and what to do |
| --- | --- |
| The request is wrong | `invalid_request`, `invalid_phone`, `template_parameters`: fix the request. Sending it again gets the same response. |
| The 24 hours passed | `outside_window`: send a template with a new `Idempotency-Key`. |
| The customer has not agreed | `no_consent`: record consent, then send with a new `Idempotency-Key`. |
| Too many requests | `rate_limited`: wait as many seconds as `Retry-After` says, then retry. |
| Our side or the network failed | `server_error` or a timeout: retry with the same `Idempotency-Key`. |
| The channel cannot send | `channel_unavailable`, `meta_payment`, `payment_required`: ask the client to reconnect or add a card at Meta, or pay the invoice. |

## Retrying safely

Retry only after a network error, `429` or `5xx`, with the same `Idempotency-Key` and body, and wait longer each time. A `4xx` response does not change on its own. A refused send keeps its key, so send the corrected one with a new key.

## Errors after the response

A message can also fail once it was accepted: the channel did not deliver it, or Meta refused it. It turns `failed` or `refused`, a `message.status` or `message.refused` event arrives, and `error.code` says why. [Errors](https://airbox.kz/docs/api/errors.md) lists every code.

## Asking us

Every response carries `X-Request-Id`, and an error body repeats it as `request_id`. Log it. The workspace's **Requests** page lists its calls of the last 30 days, each with its id. When something looks wrong, send it to us with your question.