SMS OTP API: how to send verification codes by SMS
How to send one-time login and verification codes by SMS with the DiceX SMS OTP API: the endpoints, the request, templates, cost and the checks your app still has to do.
4 min read
An SMS OTP API lets your backend send a one-time password, such as a login or verification code, to a user's phone as a text message. With DiceX you send these codes through the OTP API with ready templates, authenticate with one API key in the request header, and pay from the same wallet as your other DiceX services. This guide shows the endpoints, what a request contains and what your own application still has to handle.
Why use SMS for one-time codes
An SMS reaches a phone without internet access or an installed app. For a login code, that matters: the user may be on a new device, offline from data, or without your app installed yet. The code still arrives as a plain text message.
SMS one-time codes are commonly used for:
- signing in without a password, or as a second step after one
- confirming a phone number at sign-up
- approving a sensitive action, such as changing account details
- recovering access to an account
How the SMS OTP API flow works
A typical verification flow has five steps:
- The user enters a mobile number in your app.
- Your backend calls the DiceX OTP API with that number and a template.
- DiceX sends the SMS, and the response returns a message ID, the code and the cost.
- The user types the code into your app.
- Your backend compares what the user typed with the code it stored, and signs the user in or rejects the attempt.
The comparison in step 5 happens in your application. Store the code server-side with an expiry, and never send it back to the browser.
The endpoints you need
All requests go to the DiceX gateway at https://gateway.dicex.me, with your key in an ApiKey header.
Endpoint | Method | What it does |
|---|---|---|
| POST | Sends a one-time code |
| GET | Checks the OTP service status |
| GET | Returns a template's parameters and text, by template code |
| POST | Returns the status of one or more messages by ID |
The complete, current reference is at docs.dicex.me. Check it before you build, since field details can change.
What a send request contains
The OTP send request is JSON. The reference lists these fields:
templateCode: the OTP template to usemobile: the recipient's numbercode: the code to send, if you generate it yourselfmessage: message text, where the template uses itlineNumber: the sender to send fromlength: a code length valuelang: the template language
A minimal call looks like this (values are placeholders):
```bash
curl -X POST "https://gateway.dicex.me/api/v1/Otp/Send"
-H "ApiKey: YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{"templateCode": 1234, "mobile": "RECIPIENT_NUMBER", "code": 482913}'
```
To see which parameters a template expects before you call it, request GetOtpTemplateParameters with the template code. It returns the parameter names and the template's message.
Templates and message length
Ready templates keep OTP messages short and consistent. A short message matters for cost: a long SMS is split into parts and each part is charged separately. Text in Arabic or other non-Latin scripts fits fewer characters per part than Latin text, so keep the template to the code and one line of context, for example "Your sign-in code is 482913."
Sender ID and countries
DiceX sends SMS to mobile numbers in countries around the world. For a verification code, a recognisable sender helps users trust the message:
- Where the destination country allows it, the code arrives with your brand's name as the sender.
- Elsewhere, it arrives with the sender type that country accepts.
- Some countries require the sender to be registered first.
If your users are spread across countries, plan sender registration before launch rather than after the first failed sign-ins.
Cost and status
Each OTP SMS is paid from your DiceX wallet. The price depends on the destination country and operator, the number of parts and your account's rates, and the send response includes the cost of that message.
Whether each message arrives also depends on the destination operator's rules and the recipient's phone. Use CheckSmsStatus with the message IDs to see what happened, and log failures by country so you can spot a sender or route problem early.
Security checks your app should do
The API sends the code; protecting the flow is your application's job. A few practices worth building in:
- Expire codes quickly. A code should only work for a short window.
- Limit attempts. Lock or slow down after a few wrong entries.
- Limit resends. Add a wait before a new code can be requested, per number and per IP address.
- Use each code once. Invalidate it as soon as it is used.
- Keep codes out of logs. Store them hashed if you can.
- Keep the API key on the server. Never put it in a mobile app or browser code.
Next step
Create an API key in the panel at sms.dicex.me, read the OTP and SMS reference, and send a test code to your own number. For an overview of SMS on DiceX, see the SMS hub and the developer hub, or the product page at dicex.me.
Frequently asked questions
How do I authenticate with the DiceX OTP API?
With one API key sent in the request header. You create and manage API keys in the DiceX panel.
Why send login codes by SMS rather than an app?
An SMS reaches a phone without internet access or an installed app, so a login code does not depend on either.
How much does an OTP SMS cost?
The price depends on the destination country and operator and your account's rates. It is paid from your DiceX wallet, and the send response includes the cost.
Can the code arrive with my brand name as the sender?
Where the destination country allows it, yes. Elsewhere the message arrives with the sender type that country accepts, and some countries require the sender to be registered first.
Related articles
Bulk SMS service: a complete guide to sending SMS from a panel or an API
What a bulk SMS service does, how sender IDs and per-country pricing work, and how to send promotions, notifications and one-time codes from the DiceX panel or SMS API.
How to run an SMS marketing campaign, step by step
A practical, step-by-step way to plan, write, schedule and measure an SMS marketing campaign, with the cost checked before you send and clicks counted after.