ReferenceREST · JSON · HTTPS

OTP API rate limits

The limits on every send, how they are counted, and how to build your OTP flow so real users never notice them while abusers hit them fast.

Every OTP API that sends SMS needs limits. Without them, one script hammering your sign-up form can send thousands of codes and drain your balance in minutes. DiOTP checks a set of limits on every send. When one is reached, the API answers 429 with a code that says which limit it was. Nothing is sent and nothing is charged.

The limits

LimitDefaultWindowError code
Resend to the same number1 code30 secondsresend_cooldown
Codes per number3last 60 minutesphone_hourly_limit
Codes per number10last 24 hoursphone_daily_limit
Sends per API key30last 60 secondsapi_key_minute_limit
Sends per accountaccount ceilinglast 60 secondsrate_limited
Verify attempts per request5life of the code (5 minutes)too_many_attempts

Every limit returns HTTP 429 and the usual error body:

Response 429
{
  "error": {
    "code": "resend_cooldown",
    "message": "a code went to this number moments ago; wait before sending another",
    "request_id": "3f1c9a0e5b7d4e2a8c6f1b0d9e8a7c6b"
  }
}

How limits are counted

  • Per number, across every key. The cooldown and the hourly and daily limits count codes sent to one mobile number from all of your API keys together. A second key does not reset them.
  • Per key. The 30 a minute limit is counted separately for each API key.
  • Per account. The account ceiling counts all sends from all keys in the last minute.
  • Rolling windows. Each window is measured back from the moment of the request, not from the top of the hour or midnight.
  • Only sent codes count. A send that was refused, by a limit or any other error, does not count towards the limits.
  • In order. The cooldown is checked first, then the hourly and daily limits, then the key, then the account. You get the first one that applies.

Pass the number the same way every time, as the 10-digit number with country_code 91, so every send to one person is counted against one number.

Design around them: resend timers

Users often press Resend because the first SMS has not arrived yet. Show a countdown of 30 seconds after each send and enable the Resend button only when it ends. That one change keeps genuine users away from resend_cooldown. After the third code in an hour, replace the button with a short message asking the user to try later, rather than letting them hit phone_hourly_limit.

Exponential backoff

Some 429 and 503 responses are worth retrying from your server; others are not. Retry api_key_minute_limit, rate_limited and sending_unavailable after a delay that doubles each time, for example 1, 2, then 4 seconds, with a little random jitter, and give up after a few tries. Never retry the per-number limits automatically: the answer will not change until the window moves on, so tell the user instead.

The Idempotency-Key does not count twice

Send an Idempotency-Key header with every send, one per user action. If a request times out and you retry with the same key and the same body, and the first attempt succeeded, the API returns the original response. It sends nothing new and the retry does not count against any limit or your test messages. If the first attempt failed, nothing was stored for that key, so the retry is a real new attempt. Reusing a key with a different body returns 409 idempotency_key_reused. Details are on Send an OTP.

Add per-IP limits in your own app

DiOTP limits by number, key and account. It never sees your user’s IP address, device or session, because the request comes from your server. Attackers who pump SMS traffic rotate through many numbers, so per-number limits alone will not stop them. Add your own checks before you call the API:

  • A limit per IP address and per session on your send-code endpoint.
  • A CAPTCHA or similar challenge after a few requests from one visitor.
  • Blocks on number ranges or countries you do not serve.
  • Alerts when sends per minute jump above your normal level.

The SMS pumping protection guide and OTP security best practices go further. For every 429 code and its fix, see API error codes. Need more headroom for real traffic? Talk to us.

Rate limits: FAQ

No. When a limit is hit the API returns 429 before anything is sent, so nothing is delivered and nothing is charged. Only a message actually handed to the network is charged.

Need help integrating?

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