The short version
OTP (one-time password) delivery is a critical path in authentication systems. When users request a login code or phone verification, the SMS API is the bridge between your application logic and the carrier network. This guide covers API implementation patterns, webhook-based delivery tracking, idempotent request design, and operational considerations for production OTP flows.
- Send OTPs via REST API with explicit expiration and retry windows
- Track delivery state through webhooks and error codes
- Design for idempotency to prevent duplicate OTP sends
- Implement rate limiting to protect against SMS pumping
- Configure sender IDs and verify carrier pre-approval for high-volume routes
OTP API Implementation
Choose how to verify the code before sending it. Use the SMS API if your app already generates and checks its own codes. Use Notilify’s OTP API if you want Notilify to generate, send, and verify them. Replace the example API key, phone number, sender, and code with values from your app.
When your app checks the code, send the SMS with POST /v1/message. Use to for the recipient’s number in E.164 format, from for an approved sender ID or phone number, and message for the SMS text.
POST https://api.notilify.com/v1/message
Authorization: Bearer YOUR_NOTILIFY_API_KEY
Content-Type: application/json
{
"to": "+12025550123",
"from": "YOUR_APPROVED_SENDER",
"message": "Your verification code is 847293"
}Save data.message_id to track delivery alongside the pending attempt. Your app checks the code, enforces expiry and attempt limits, and accepts the code only once.
When Notilify checks the code, use POST /v1/otp with channel set to sms and phoneNumber set to the recipient’s number. Save the returned data.otpId with the pending verification in your app.
POST https://api.notilify.com/v1/otp
Authorization: Bearer YOUR_NOTILIFY_API_KEY
Content-Type: application/json
{
"channel": "sms",
"phoneNumber": "+12025550123"
}Send the code the user enters to POST /v1/otp/verify. Complete the pending verification only if Notilify approves the code and returns the same data.otpId your app saved for that attempt.
POST https://api.notilify.com/v1/otp/verify
Authorization: Bearer YOUR_NOTILIFY_API_KEY
Content-Type: application/json
{
"otp": "CODE_ENTERED_BY_USER"
}Delivery webhooks help you track an SMS. The verification result tells you whether to complete the pending verification in your app.
Production OTP Implementation Checklist
- If your app manages its own codes, generate them with a cryptographically secure random source.
- For codes your app manages, store a code hash, expiry time, and attempt count. For Notilify managed verification, store the OTP ID with the pending attempt.
- Rate limit resend requests and reuse the pending attempt when appropriate to avoid sending duplicate messages.
- Set up webhooks for delivery receipts but never gate authentication on webhook callbacks
- Record the message ID when available, a masked phone number, and the delivery status or error for debugging.
- Monitor for delivery failures and alert on elevated error rates by route
Reliable OTP Delivery Starts at the API Layer
OTP verification depends on predictable message delivery and clean integration with your auth system. The SMS API handles the carrier abstraction, sender ID routing, and delivery state tracking—so your team focuses on authentication logic, not telecom complexity.
For production OTP flows, prioritize idempotent request design, webhook-based observability, and explicit code expiration rules. Notilify's transactional SMS API provides the message_id tracking and error code visibility you need to debug delivery issues without carrier support tickets.
How do I handle OTP delivery failures in my application?
Check the error_code in webhook payloads or API responses. Common failure codes include INVALID_NUMBER, CARRIER_REJECT, and ROUTE_UNAVAILABLE. For transient errors (network timeouts, carrier queuing), implement exponential backoff with a 3-attempt max before marking the attempt failed. For invalid numbers, fail fast and prompt user to verify the phone number.
Should my authentication flow wait for SMS delivery confirmation?
Use delivery receipts to track SMS progress. If your app manages its own code, check it against the pending attempt. If Notilify manages the code, wait for an approved result with the OTP ID saved for that attempt.
How do I prevent duplicate OTP sends if the user clicks 'Resend Code'?
Apply a resend cooldown in your app and reuse the pending attempt when appropriate. Keep its message ID for SMS tracking or its OTP ID for Notilify managed verification.
What sender ID should I use for OTP messages?
For US OTPs, use a verified short code or toll-free number registered for A2P 10DLC. For international routes, sender ID requirements vary by country—some require pre-registration while others allow alphanumeric sender IDs. Notilify provides route-specific sender ID guidance in your dashboard.
Read API docs
Use Notilify to build transactional SMS with clearer delivery state, sender planning, and support visibility.
Read API docs