# Errors

Every error answers JSON with a `detail`, an `error` object and the `request_id` of the call. The `X-Request-ID` header carries the same id; quote it when you write to support.

## Relay refused the request

```json
{"detail": "Unknown, expired or revoked API key.",
 "error": {"source": "relay", "retryable": false}, "request_id": "req_3f1c9a0b2d4e6f81"}
```

| Status | Meaning | Retry? |
|---|---|---|
| `401` | Missing, unknown, expired or revoked API key. | No, fix the key. |
| `402` | No active subscription (only when billing is enforced). | No, subscribe under Billing. |
| `403` | Endpoint not allowed for this key (e.g. `/test/inbound` with a live key). | No. |
| `404` | Unknown message, number or link id. | No. |
| `409` | No number connected, or the same `Idempotency-Key` is still in progress. | Yes, after connecting or after a second. |
| `422` | Validation failed: phone number, template variables, body, idempotency key reused with a different body. `detail` says what. | No, fix the request. |
| `429` | Rate limit or test-mode cap. Wait `Retry-After` seconds. | Yes. |

## Meta rejected the request

When Meta refuses a send or a template, Relay answers `502` and passes Meta's error through unchanged. A failed send is still logged; `message_id` points at it.

```json
{"detail": "Message failed to send because more than 24 hours have passed since the customer last replied to this number.",
 "error": {"source": "meta", "http_status": 400, "code": 131047, "subcode": null,
           "message": "Re-engagement message", "details": "…", "fbtrace_id": "A4mlJQZRCIOpXKHvZBefkpq", "retryable": false},
 "message_id": 42, "request_id": "req_9a7b…"}
```

`retryable` is `true` for Meta's rate limits and temporary errors; retry those with backoff. Everything else needs a change on your side or in Meta's Business Manager.

## What to do, by Meta code

| Code | Meaning | What to do |
|---|---|---|
| 131047 | More than 24 h since the customer last wrote. | Send a template instead of free text. |
| 131026 | Message undeliverable (not on WhatsApp, old app, or blocked). | Fall back to SMS or e-mail; do not retry. |
| 131049 | Meta held back a marketing message for ecosystem health. | Retry later, at most once a day; send fewer marketing messages. |
| 130429 | Throughput limit (coexistence numbers: 20 messages per second). | Slow down; retry with backoff. |
| 131056 | Too many messages to the same customer in a short time. | Space them out. |
| 132000 | Template parameter count does not match. | Send exactly one `params` entry per `{{n}}`. |
| 132001 | Template does not exist in that language, or is not approved. | Check `GET /templates` name, language and status. |
| 132012 | Parameter format wrong (empty, too long, line breaks). | Clean the values. |
| 131042 | Payment problem on the WhatsApp Business Account. | The shop adds or fixes a payment method in WhatsApp Manager. |
| 368 | Account temporarily blocked for policy violations. | Check Business Support Home; stop sending until cleared. |
| 190 | Access token expired or revoked (e.g. the shop disconnected Relay in the app). | Reconnect the number in the dashboard. |

Meta's full list: [error codes](https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes).

## Delivery failures

A message Meta accepted can still fail later. That arrives as a `failed` status by webhook, with Meta's `errors[]` array, and as `status: "failed"` with an `error` text on `GET /messages/{id}`.
