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
| Limit | Default | Window | Error code |
|---|---|---|---|
| Resend to the same number | 1 code | 30 seconds | resend_cooldown |
| Codes per number | 3 | last 60 minutes | phone_hourly_limit |
| Codes per number | 10 | last 24 hours | phone_daily_limit |
| Sends per API key | 30 | last 60 seconds | api_key_minute_limit |
| Sends per account | account ceiling | last 60 seconds | rate_limited |
| Verify attempts per request | 5 | life of the code (5 minutes) | too_many_attempts |
Every limit returns HTTP 429 and the usual error body:
{
"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.
