This quickstart takes you from a new account to a verified one-time password in five steps. DiOTP does the hard parts: it generates the code, sends it by SMS, keeps it for five minutes and checks what your user types. Your server makes two HTTPS calls and never sees or stores the code. All you need is a terminal with cURL and the phone you sign up with.
The five steps
- Sign up. Create a free account and verify your mobile number. Your account starts in test mode, and test messages go only to that number.
- Copy a test key. Open API keys in the dashboard, create a key and copy it. It is shown only once. Store it on your server in an environment variable named DIOTP_API_KEY.
- Send an OTP to your own number with cURL. Call POST /v1/otp/send with your API key and the 10-digit number you verified at sign-up. Keep the request_id from the response.
- Verify the code. Read the code from the SMS on your phone and call POST /v1/otp/verify with the request_id and the code. A 200 response with verified true means the number is confirmed.
- Move both calls into your backend. Copy the Node.js, Python or PHP version of the send and verify calls into your server code, with the API key read from the environment.
1. Sign up
Create your account with your name, company, email and mobile number. We send a code to that number to confirm it is yours. That verified number matters: while your account is in test mode, it is the only number DiOTP will send to. Use a phone you have with you.
2. Copy a test key
In the dashboard, open API keys and create a key. Give it a name you will recognise later, such as the app or the environment. The full key is shown once and then stored only as a hash, so copy it straight into your server’s environment:
export DIOTP_API_KEY="paste-your-key-here"
There are no separate test and live keys. The key you create now keeps working when your account goes live. Keep it on your server only, never in a mobile app or front-end code.
3. Send an OTP to your own number with cURL
Replace YOUR_VERIFIED_NUMBER with the 10-digit mobile number you signed up with, digits only, and run:
curl -X POST https://api-diotp.diorbit.com/v1/otp/send \
-H "Authorization: Bearer $DIOTP_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 5f2b8c1e-signup-YOUR_VERIFIED_NUMBER" \
-d '{
"to": "9876543210",
"country_code": 91,
"channel": "sms",
"purpose": "signup"
}'A successful send returns 200 with a request id and the time the code expires:
{
"request_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"channel": "sms",
"expires_at": "2026-11-16T10:05:00+00:00"
}Keep the request_id. You need it to verify. The SMS arrives on the phone you signed up with. The full list of fields, including purpose and template, is on Send an OTP.
4. Verify the code
Put the request id from step 3 and the code from your SMS into this call:
curl -X POST https://api-diotp.diorbit.com/v1/otp/verify \
-H "Authorization: Bearer $DIOTP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"code": "482913"
}'A 200 response with verified set to true means the code matched and the number is confirmed. A wrong code returns 400 invalid_code, and each request allows five tries within five minutes. Every outcome is described on Verify an OTP, and every error on API error codes.
5. Node.js, Python and PHP
For Node.js and Python, the quickest way is the official SDK. PHP and other languages use the plain REST calls below. Each SDK reads the key from the environment, sends an Idempotency-Key with every send, retries network errors and turns every error into a typed exception.
Node.js SDK
npm install @diorbit/diotp
import { DiOTP } from '@diorbit/diotp'
const diotp = new DiOTP() // reads DIOTP_API_KEY
const { requestId } = await diotp.send({ to: '9876543210' }) // country code 91 by default
// Later, with the code your user typed:
const result = await diotp.verify({ requestId, code: '482913' })
console.log(result.verified) // truePython SDK
pip install diotp
from diotp import DiOTP, InvalidCodeError
client = DiOTP() # reads DIOTP_API_KEY
otp = client.send("9876543210") # country code 91 by default; keep otp.request_id
try:
client.verify(otp.request_id, "482913") # the code the user typed
print("verified")
except InvalidCodeError:
print("wrong code, try again")More on each SDK, including error handling and retries, is on the SDKs page.
Alternative: the plain REST calls
No dependency at all: the same two calls with your own HTTP client. Pick a tab. Each example reads the key from the environment and sends an Idempotency-Key, so a retried send after a timeout never texts your user twice.
Send
curl -X POST https://api-diotp.diorbit.com/v1/otp/send \ -H "Authorization: Bearer $DIOTP_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 5f2b8c1e-signup-9876543210" \ -d '{ "to": "9876543210", "country_code": 91, "channel": "sms", "purpose": "signup" }'
const res = await fetch("https://api-diotp.diorbit.com/v1/otp/send", { method: "POST", headers: { Authorization: `Bearer ${process.env.DIOTP_API_KEY}`, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID(), }, body: JSON.stringify({ to: "9876543210", country_code: 91, channel: "sms", purpose: "signup", }), }); const otp = await res.json(); // Keep otp.request_id: you need it to verify.
import os, uuid, requests res = requests.post( "https://api-diotp.diorbit.com/v1/otp/send", headers={ "Authorization": f"Bearer {os.environ['DIOTP_API_KEY']}", "Idempotency-Key": str(uuid.uuid4()), }, json={ "to": "9876543210", "country_code": 91, "channel": "sms", "purpose": "signup", }, timeout=10, ) otp = res.json() # Keep otp["request_id"]: you need it to verify.
<?php $ch = curl_init("https://api-diotp.diorbit.com/v1/otp/send"); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ "Authorization: Bearer " . getenv("DIOTP_API_KEY"), "Content-Type: application/json", "Idempotency-Key: " . bin2hex(random_bytes(16)), ], CURLOPT_POSTFIELDS => json_encode([ "to" => "9876543210", "country_code" => 91, "channel" => "sms", "purpose" => "signup", ]), ]); $otp = json_decode(curl_exec($ch), true); // Keep $otp["request_id"]: you need it to verify.
Verify
curl -X POST https://api-diotp.diorbit.com/v1/otp/verify \ -H "Authorization: Bearer $DIOTP_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "request_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "code": "482913" }'
const res = await fetch("https://api-diotp.diorbit.com/v1/otp/verify", { method: "POST", headers: { Authorization: `Bearer ${process.env.DIOTP_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ request_id: requestId, code: codeTheUserTyped }), }); if (res.ok) { // The number is verified: sign the user in. } else { const { error } = await res.json(); // e.g. error.code === "invalid_code" }
res = requests.post(
"https://api-diotp.diorbit.com/v1/otp/verify",
headers={"Authorization": f"Bearer {os.environ['DIOTP_API_KEY']}"},
json={"request_id": request_id, "code": code_the_user_typed},
timeout=10,
)
if res.ok:
pass # The number is verified: sign the user in.
else:
error = res.json()["error"] # e.g. error["code"] == "invalid_code"<?php $ch = curl_init("https://api-diotp.diorbit.com/v1/otp/verify"); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ "Authorization: Bearer " . getenv("DIOTP_API_KEY"), "Content-Type: application/json", ], CURLOPT_POSTFIELDS => json_encode([ "request_id" => $requestId, "code" => $codeTheUserTyped, ]), ]); $body = json_decode(curl_exec($ch), true); $verified = curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;
In a real sign-in flow, your server calls send when the user asks for a code, stores the request id against the user’s session, and calls verify when they type the code. Sign the user in only on a 200.
Test mode notes
- Test messages are free and go only to your verified number. Any other number returns 403
trial_restricted. - The dashboard shows how many free test messages are left. When they run out, a send returns 402
trial_used_up. - Limits apply in test mode too: one code to the same number every 30 seconds, and three an hour. See rate limits.
- Test sends are real messages on the real network, not simulated responses. More on test mode.
Going live
When your integration works, ask to go live from Account in the dashboard. We check your business details, and once approved you recharge your prepaid wallet and send to any number with the same key and the same code. You can start on our shared DLT sender the same day and add your own header and templates later, with no code change. See pricing for per-message rates.
Next steps
- Send an OTP: every field, the response and idempotency.
- Verify an OTP: wrong, expired and locked codes.
- Test mode: what you can and cannot do before going live.
- API error codes: every code, its cause and the fix.
