ReferenceREST · JSON · HTTPS

API error codes

Every error the DiOTP OTP API can return to your account, with its HTTP status, what causes it and what to do. Branch on the code; it never changes.

When a request fails, the API returns a non-2xx HTTP status and a JSON body in one fixed shape. This page lists every code your account can receive from sending, verifying, your account and usage endpoints, with the cause and the fix for each. Use it to decide what your server does next and what your user sees.

The error envelope

Every error, from every endpoint, has the same three fields:

Error body
{
  "error": {
    "code": "phone_hourly_limit",
    "message": "this number has had its hourly allowance",
    "request_id": "3f1c9a0e5b7d4e2a8c6f1b0d9e8a7c6b"
  }
}
  • code: a short, stable identifier in lower case. Your code branches on this. Codes are never renamed.
  • message: one sentence for a person to read. Log it, or show it to your team. Wording may improve over time, so do not parse it.
  • request_id: an identifier for this API call, also sent in the X-Request-Id response header. Quote it when you contact support.

The request_id in an error is the id of the API call, not the OTP request id that a successful send returns. Store both in your logs.

All error codes

Sorted by HTTP status. The second column says which call can return the code.

StatusCodeCallCauseFix
400invalid_codeverifyThe code does not match the one sent. Each wrong try uses one of the five attempts.Let the user try again. When the attempts are used up, send a new code.
401unauthorizedanyThe Authorization header is missing, or the key is wrong or revoked.Send Authorization: Bearer followed by your key. Check the environment variable on the server; create a new key if it was revoked.
402trial_used_upsendYour free test messages are used up.Ask to go live from Account in the dashboard.
402insufficient_balancesendYour live account’s wallet holds less than the price of one message. Nothing was sent or charged.Recharge the wallet, then send again.
403trial_restrictedsendIn test mode, the number or country code is not the one you verified at sign-up.Send to your own verified number, or go live.
403account_suspendedsendSending is paused on this account.Contact support.
403template_not_approvedsendThe template is in our library but is not approved for your account yet. The message reads: request this template from the Templates page in your dashboard; it is available after our team approves it.Request the template from the Templates page and send again once it shows Sendable now, or leave template out to use the default.
404not_foundverifyThe request_id is unknown to your account.Pass the request_id from the send response exactly as returned.
409already_verifiedverifyThis request was already verified successfully.Treat the number as verified. Do not verify the same request twice.
409not_pendingverifyThe request has ended: it already expired, or it was locked after too many attempts.Send a new code.
409idempotency_key_reusedsendThe Idempotency-Key was used before with a different request body.Use a new key for each user action; reuse a key only to retry the identical request.
409channel_not_enabledsendThe channel you asked for, such as whatsapp, is not switched on for your account.Send with channel sms, or contact support to enable the channel.
410expiredverifyMore than five minutes passed since the code was sent.Send a new code.
422invalid_requestanyA field is missing or malformed, for example to is not 6 to 15 digits or code is not 4 to 10 characters. The message names the field.Fix the field named in the message.
422template_not_availablesendThe template id is unknown, cannot be sent on your account, or was used with a channel other than sms.Copy the id from the Templates page, or leave template out to use the default.
429resend_cooldownsendA code went to this number less than 30 seconds ago.Wait, and show a resend timer in your app.
429phone_hourly_limitsendThis number has had three codes in the last hour.Ask the user to try later. Retrying now will not help.
429phone_daily_limitsendThis number has had ten codes in the last 24 hours.Ask the user to try tomorrow, or offer another way to sign in.
429api_key_minute_limitsendThis API key sent 30 codes in the last minute.Back off and retry, or spread traffic over time.
429rate_limitedsendYour account reached its per-minute sending ceiling.Back off and retry with exponential delays. Contact us if your normal traffic needs more.
429test_limitsendYour live account is switched to test mode and has used its daily free test messages.Switch back to live in the dashboard, or wait until tomorrow (UTC).
429too_many_attemptsverifyFive attempts were already used on this request; it is now locked.Send a new code.
503sending_unavailablesendWe could not send this message right now. Nothing was charged.Retry after a short wait with the same Idempotency-Key, using exponential backoff.
A channel value other than sms or whatsapp is refused with HTTP 422 before anything is sent. Handle any 422 the same way: fix the request, do not retry it.

Which errors each call can return

POST /v1/otp/send can return the authentication, test mode, account, balance, validation, idempotency, channel, template and limit errors, and 503 when a message cannot go out right now. The checks run in a fixed order: authentication, then the request body, then a replayed Idempotency-Key, then test mode rules, then rate limits, then your balance. A replay with a known Idempotency-Key returns the first response before any limit is checked.

POST /v1/otp/verify returns invalid_code, not_found, already_verified, not_pending, expired, too_many_attempts and invalid_request. Note the order of events on one request: wrong codes return 400 until five attempts are used, the next try returns 429 too_many_attempts, and every try after that returns 409 not_pending. Likewise an expired code returns 410 once, then 409 not_pending.

GET /v1/me and GET /v1/usage return 401 unauthorized for a bad key, and usage returns 422 invalid_request when the period is not in YYYY-MM form. See account and usage.

Handling errors well

  • Show your user a message for the codes they can act on: a wrong code, an expired code, or a resend that came too soon. Everything else is for your logs.
  • Never show the raw message to end users. Map codes to your own words, in their language.
  • Retry only sending_unavailable, rate_limited and api_key_minute_limit, with backoff. The rate limits page shows how.
  • Treat any other 5xx response like sending_unavailable: wait, then retry with the same Idempotency-Key.
  • Alert your team on 401, 402 and 403. They mean a configuration or account problem, not a user mistake.

New to the API? Start with the quickstart. Errors you see only before going live are explained on test mode.

API error codes: FAQ

Branch on error.code. Several codes share a status, for example 429 covers five different limits and 409 covers four different conflicts, and each needs a different response in your app. Use the status only as a fallback for anything unexpected.

Need help integrating?

Our team helps with integration, DLT templates and going live.