# Errors

- Page: https://bytesms.com/docs/errors (markdown: https://bytesms.com/docs/errors.md)
- API base URL: https://api.bytesms.com/api (public resources under /api/v1)
- Auth: `Authorization: Bearer tp_live_…` — an API key from Dashboard → API Keys; keep it server-side (e.g. `BYTESMS_API_KEY`)
- All docs in one file: https://bytesms.com/llms-full.txt · OpenAPI 3.1: https://bytesms.com/openapi.json

The Bytesms error envelope ({ statusCode, message, name }) and every error name the API returns, with HTTP status codes.

## Error shape

Every `/api/v1` error is JSON with the HTTP status, a human-readable `message` and a machine-readable `name`. Branch on `name` (and the status), never on `message`.

**422 Unprocessable Entity**

```json
{
  "statusCode": 422,
  "message": "`to` must contain at least one recipient.",
  "name": "validation_error"
}
```

Some errors add fields. Quota errors (`daily_quota_exceeded`, `monthly_quota_exceeded`) and plan-limit errors (`plan_limit_exceeded`) carry the specific `code` plus `limit` and `current`. Other errors may include a `code` when one is available. `402 insufficient_credits` adds `neededThb` and `availableThb`. Treat every extra field as optional:

**429 Too Many Requests**

```json
{
  "statusCode": 429,
  "message": "Daily email limit reached (100/100). Try again tomorrow or upgrade your plan.",
  "name": "daily_quota_exceeded",
  "code": "daily_limit_reached",
  "limit": 100,
  "current": 100
}
```

**402 Payment Required**

```json
{
  "statusCode": 402,
  "message": "Not enough prepaid credit. Top up (or turn on auto-recharge) in the dashboard under Settings → Billing.",
  "name": "insufficient_credits",
  "neededThb": 0.155,
  "availableThb": 0.04
}
```

Request-body validation failures (wrong types, invalid email addresses, unknown enum values) are returned as `422 validation_error` with the individual problems joined into `message`.

## Error names

| Status | name | When |
| --- | --- | --- |
| 401 | `unauthorized` | Missing, malformed, unknown or expired API key. |
| 401 | `restricted_api_key` | A sending_access key called an endpoint other than the email send and WhatsApp endpoints. |
| 402 | `insufficient_credits` | The over-quota recipients (or a WhatsApp message) cost more than the workspace's prepaid credit, after auto-recharge. Body adds `neededThb` / `availableThb` — see [Credits & billing](https://bytesms.com/docs/credits). |
| 403 | `restricted_api_key` | A domain-scoped key sent from another domain (or its domain was deleted), or called a /v1/whatsapp endpoint. |
| 403 | `suspended_api_key` | The API key was suspended. |
| 403 | `invalid_from_address` | The from domain is not a verified domain of this workspace (the workspace has other verified domains). |
| 403 | `validation_error` | No verified domain yet, or `onboarding@mail.bytesms.com`used to send to anyone other than your own account email or a test address. Also returned when a domain's warm-up daily volume is used up. |
| 403 | `sending_paused` | Sending is paused for the workspace (e.g. high bounce/complaint rate). |
| 403 | `account_under_review` | The workspace is under review. |
| 403 | `account_suspended` | The workspace is suspended. |
| 403 | `subscription_past_due_expired`, `subscription_unpaid`, `subscription_incomplete`, `subscription_paused`, `subscription_canceled` | The paid subscription is not in good standing (past the payment grace period, unpaid, …). |
| 403 | `plan_limit_exceeded` | A plan cap was hit; `code` says which: `api_key_limit_reached`, `domain_limit_reached`, `segment_limit_reached`, `contact_limit_reached`, `contact_limit_exceeded`, `webhook_limit_reached`, `member_limit_reached`. The body also carries `limit` (the plan cap) and `current` (the count when the request was made). |
| 404 | `not_found` | The resource does not exist in this workspace (ids of other workspaces are 404 too). |
| 409 | `idempotency_key_conflict` | The Idempotency-Key was already used with a different request body. |
| 409 | `domain_in_use`, `domain_pending_elsewhere` | The domain is verified in another workspace, or claimed there within the last 72 hours. |
| 409 | `validation_error` | Duplicate: a contact with this email already exists in the audience, a template alias is taken, a broadcast was already sent. |
| 422 | `validation_error` | The request is invalid (see message). |
| 422 | `invalid_idempotency_key` | The Idempotency-Key header is empty or longer than 256 characters. |
| 422 | `attachments_not_supported` | The request contained attachments (not supported yet). |
| 422 | `invalid_domain`, `reserved_domain` | Not a valid fully-qualified domain name, or a platform / consumer-mailbox domain that can't be added. |
| 429 | `rate_limit_exceeded` | Too many requests per second — see [Rate limits](https://bytesms.com/docs/rate-limits). |
| 429 | `daily_quota_exceeded` | The plan's daily email limit (recipients per UTC day) is used up. |
| 429 | `monthly_quota_exceeded` | The plan's monthly quota is used up on a plan without overage (Free). Paid plans continue from prepaid credit. |
| 5xx | `application_error` | Something went wrong on our side, or a sending server was unreachable. Retry with backoff. |

## Retrying

Retry `429 rate_limit_exceeded` after the `retry-after` header and `5xx` errors with exponential backoff. Retry `402 insufficient_credits` once the workspace has topped up. When you retry a send, use an [Idempotency-Key](https://bytesms.com/docs/idempotency)so a request that actually succeeded is not sent twice. Don't retry other 4xx errors unchanged — they fail the same way.

> **Note: Legacy endpoint**
>
> The legacy `POST /api/v1/emails/send` is not wrapped in this envelope: request-validation failures come back as `400` with `{ statusCode, message: string[], error }`, and it returns the full internal message row on success. New integrations should use `POST /api/v1/emails`.
