Errors, retries & idempotency
Error codes and how to retry safely.
Error format
400 Bad Request
{
"success": false,
"error": {
"code": "VALIDATION_FAILED",
"message": "Request validation failed",
"details": [{ "field": "mobile", "message": "mobile must be longer than or equal to 8 characters" }]
},
"requestId": "0199491c-8f3a-7c2e-9b1d-5e7f3a2c4b6d"
}- Branch on
error.code. Codes are never renamed or reused; new codes may be added, so fall back to the HTTP status. messageis for humans and may change. Do not show it to end users verbatim or parse it.details[].fieldpoints at the offending input, e.g.variables.order.
Error codes
Authentication and access
| Code | HTTP | Meaning | Retry |
|---|---|---|---|
AUTHENTICATION_REQUIRED | 401 | No API key was sent. | Fix the request or configuration first |
API_KEY_INVALID | 401 | The key is malformed or unknown. | Fix the request or configuration first |
API_KEY_REVOKED | 401 | The key was revoked. | Fix the request or configuration first |
API_KEY_EXPIRED | 401 | The key passed its expiry date. | Fix the request or configuration first |
INSUFFICIENT_SCOPE | 403 | The key lacks the scope named in details. | Fix the request or configuration first |
IP_NOT_ALLOWED | 403 | The calling IP is not on the key allow-list. | Fix the request or configuration first |
PROJECT_INACTIVE | 403 | The project is archived. | Fix the request or configuration first |
PROJECT_SUSPENDED | 403 | SMS21 suspended the project; contact support. | Fix the request or configuration first |
API_KEY_SUSPENDED | 403 | SMS21 suspended the key; contact support. | Fix the request or configuration first |
COMPANY_SUSPENDED | 403 | The company is suspended by SMS21. | Fix the request or configuration first |
Request
| Code | HTTP | Meaning | Retry |
|---|---|---|---|
VALIDATION_FAILED | 400 | A field is missing, malformed or unknown; see details. | Fix the request or configuration first |
INVALID_RECIPIENT | 400 | Not a valid mobile number in international format. | Fix the request or configuration first |
IDEMPOTENCY_KEY_INVALID | 400 | Idempotency-Key is not 1-128 of A-Z a-z 0-9 . _ : - | Fix the request or configuration first |
IDEMPOTENCY_KEY_REUSED | 409 | The key was already used with a different body. | Do not retry |
NOT_FOUND | 404 | No such resource in this project. | Do not retry |
PAYLOAD_TOO_LARGE | 413 | The body exceeds the size limit. | Fix the request or configuration first |
BULK_TOO_MANY_RECIPIENTS | 400 | A campaign holds more recipients than SMS21 accepts; split the list. | Fix the request or configuration first |
BATCH_NOT_CANCELLABLE | 409 | The campaign already finished, failed or was cancelled. | Do not retry |
RECIPIENT_SUPPRESSED | 400 | The number is on your opt-out list. | Fix the request or configuration first |
UNSUPPORTED_MEDIA_TYPE | 415 | Send Content-Type: application/json. | Fix the request or configuration first |
Content, DLT and templates
| Code | HTTP | Meaning | Retry |
|---|---|---|---|
TEMPLATE_REQUIRED | 400 | Live SMS to this country needs an approved DLT template. | Fix the request or configuration first |
TEMPLATE_VARIABLES_INVALID | 400 | Variables are missing, unexpected or too long. | Fix the request or configuration first |
TEMPLATE_CATEGORY_NOT_ALLOWED | 400 | The template category does not fit this message type. | Fix the request or configuration first |
MESSAGE_TOO_LONG | 400 | More than 10 SMS segments. | Fix the request or configuration first |
OTP_TEMPLATE_INVALID | 400 | The OTP template has no {{otp}} variable. | Fix the request or configuration first |
WHATSAPP_TEMPLATE_INVALID | 400 | Wrong WhatsApp template for this endpoint. | Fix the request or configuration first |
TEMPLATE_NOT_APPROVED | 409 | The template is not approved (yet). | Fix the request or configuration first |
DLT_ENTITY_NOT_APPROVED | 409 | The DLT entity is not approved. | Fix the request or configuration first |
SENDER_ID_NOT_APPROVED | 409 | The sender ID (header) is not approved. | Fix the request or configuration first |
OTP
| Code | HTTP | Meaning | Retry |
|---|---|---|---|
OTP_INVALID | 400 | Wrong code; details give the attempts left. | Do not retry |
OTP_EXPIRED | 410 | Expired, or superseded by a newer OTP. | Do not retry |
OTP_ALREADY_VERIFIED | 409 | The request was already verified once. | Do not retry |
OTP_ATTEMPTS_EXCEEDED | 429 | Locked after too many wrong codes. | Do not retry |
OTP_RESEND_COOLDOWN | 429 | Too soon to send another OTP to this number. | Retry after Retry-After / later |
DESTINATION_NOT_ALLOWED | 400 | OTPs are not enabled for this country. | Do not retry |
Billing and platform controls
| Code | HTTP | Meaning | Retry |
|---|---|---|---|
INSUFFICIENT_BALANCE | 402 | Live traffic: the wallet cannot cover the message. | Fix the request or configuration first |
WALLET_SUSPENDED | 403 | Live sending is suspended for the wallet. | Fix the request or configuration first |
PRICING_NOT_CONFIGURED | 409 | No price applies; contact SMS21. | Fix the request or configuration first |
DESTINATION_BLOCKED | 403 | The destination is blocked by SMS21 risk controls. | Do not retry |
DAILY_LIMIT_EXCEEDED | 429 | The company daily live message limit is reached. | Retry after Retry-After / later |
SENDING_PAUSED | 503 | SMS21 paused sending on this channel. | Retry after Retry-After / later |
Transient
| Code | HTTP | Meaning | Retry |
|---|---|---|---|
RATE_LIMITED | 429 | Request rate limit; wait Retry-After seconds. | Retry with the same Idempotency-Key |
SERVICE_UNAVAILABLE | 503 | A dependency is temporarily unavailable. | Retry with the same Idempotency-Key |
INTERNAL_ERROR | 500 | Unexpected error; quote the requestId to support. | Retry with the same Idempotency-Key |
Retrying safely
| Failure | Sends (OTP send, SMS, WhatsApp) | OTP verify | Reads |
|---|---|---|---|
| Network error or timeout | Retry with the same Idempotency-Key | Do not retry | Retry |
| 500, 502, 503, 504 | Retry with the same Idempotency-Key (not SENDING_PAUSED) | Do not retry | Retry |
| 429 RATE_LIMITED | Wait Retry-After, then retry | Wait Retry-After, then retry | Wait, then retry |
| Other 4xx | Fix the request | Show the outcome | Fix the request |
Use exponential backoff with jitter (for example 0.5 s, 1 s, 2 s… up to 8 s) and a small retry budget.
Idempotency keys
- Header
Idempotency-Key: 1–128 characters ofA–Z a–z 0–9 . _ : -. - Accepted by
POST /otp/send,/sms/send,/whatsapp/sendand/whatsapp/template; scoped to the project. - Same key and same body → the original result, with
Idempotent-Replayed: true. Nothing is sent or charged again. - Same key, different body →
409 IDEMPOTENCY_KEY_REUSED. - Derive keys from your own IDs (
trip2all:booking:88121:confirmation) so they survive process restarts.
Why OTP verification is different
Verification cannot be made idempotent without weakening it: each attempt counts, and a code works once. If a verify call times out, ask the user to request a new code rather than retrying.