OTP API code generator for cURL, PHP, Node.js and Python
This OTP API code generator writes the two calls you need, send a code and verify it, in cURL, PHP, Node.js or Python, with your channel, test number and purpose label filled in. The code works with DiOTP's OTP without DLT, so it runs as soon as you have an account. It never asks for your API key: the generated code reads it from the DIOTP_API_KEY environment variable.
By Vivek Singh, Founder, Diorbit TechnologiesUpdated
Generate your OTP API code
cURL: send a code
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: $(uuidgen)" \
-d '{"to":"9876543210","country_code":91,"channel":"sms","purpose":"login"}'cURL: verify the code
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": "REQUEST_ID_FROM_SEND", "code": "CODE_THE_USER_TYPED"}'The code calls the same API whether you send on DiOTP's shared template or, later, on your own sender ID. If you are new to OTP without DLT, the short version is that your codes go out under DiOTP's registered DLT entity, the DIORBT header and a pre-approved OTP template, so you can send today without registering anything yourself.
How to use it
- Pick your language: cURL, PHP, Node.js or Python.
- Pick the channel: SMS, or WhatsApp if WhatsApp is switched on for your account.
- Type a test mobile number without +91. While your account is in test mode, use the number you verified at sign-up, because the free test messages go only there.
- Set a purpose label such as login or signup. It is for your own reports and does not change the message.
- Leave "Add an Idempotency-Key" ticked unless you have a reason not to. It makes retries safe.
- Copy the send code and the verify code with the Copy buttons, and run them on your server with DIOTP_API_KEY set in the environment.
The output changes as you type, so you can switch languages and compare the same call side by side.
What does the generated code do?
The send call
It posts to https://api-diotp.diorbit.com/v1/otp/send with your number, country code 91, the channel and the purpose label. DiOTP generates the code, sends it and returns a request_id and the time the code expires, five minutes later. Your server never sees the code itself. Each language reads the key from the environment: $DIOTP_API_KEY in cURL, getenv in PHP, process.env in Node.js and os.environ in Python.
With the Idempotency-Key option on, the send adds a fresh unique key: uuidgen in cURL, random_bytes in PHP, crypto.randomUUID in Node.js and uuid4 in Python. If a request times out and you retry it with the same key and body, you get the first response back and no second code is sent or charged.
The verify call
It posts the stored request_id and the code your user typed to /v1/otp/verify. A 200 response means the number is verified. The generated verify code uses placeholder variables for those two values (for example request_id and code_the_user_typed in Python), so swap in your own. A wrong code returns 400 invalid_code; an expired one returns 410.
Errors
Each sample shows where to read the error code, error.code inside the JSON body, with an example such as resend_cooldown. Branch on that code rather than the HTTP status, because several errors share a status. The OTP SMS API reference lists every code with what to do about it.
What each language needs
| Language | Needs | Good for |
|---|---|---|
| cURL | A shell with curl; uuidgen for the Idempotency-Key | Quick tests from a terminal |
| PHP | The curl extension, which most hosts have | Laravel, WordPress and plain PHP apps |
| Node.js | Node.js 18 or newer, where fetch is built in | Express, Next.js API routes and other Node backends |
| Python | The requests library; calls time out after 10 seconds | Flask, Django, FastAPI and scripts |
Does the generator ask for or store my API key?
No. The tool never asks for your API key and has no field for one. It runs entirely in your browser, makes no network calls and stores nothing. The code it writes reads the key from an environment variable called DIOTP_API_KEY on the machine that runs it.
That is also how you should run the code. Set DIOTP_API_KEY on your server, in your process manager, hosting dashboard or an untracked .env file, and keep it out of your source code, your logs and anything that ships to a browser or mobile app. Anyone who has the key can send codes on your balance. If a key leaks, create a new one in the dashboard and revoke the old one.
Run the generated code on your server only. A mobile app or web page should call your own backend, which then calls DiOTP. The Android and Flutter guide shows that pattern.
What happens when I run it?
On a new account you get 10 free test messages, sent only to the mobile number you verified at sign-up. Run the send code with that number and you receive a real SMS like this, with your company name in the message:
Text message
VM-DIORBT
482913 is your login OTP for Acme. Do not share it with anyone. Powered by Diorbit Technologies!
A send to any other number returns 403 trial_restricted until your account is live. A recharge of your prepaid wallet makes it live, and the same code then sends to any Indian mobile number at ₹0.26 to ₹0.40 per OTP plus 18% GST, with no setup or monthly fee. The limits apply from the first call: one code to a number every 30 seconds, three an hour, ten a day, and 30 sends per API key per minute. Codes blocked by a limit are not sent or charged.
For a full working flow rather than two calls, follow the Python guide, the Node.js OTP verification guide or the PHP guide. They add error messages for users, safe retries and a login view.
Questions and answers
Is the OTP code generator free?
Yes. It is free to use and needs no account. You need a DiOTP account and an API key only to run the code it writes.
Does the tool send a real OTP?
No. It only writes code in your browser. A message is sent only when you run that code on your own machine or server with a valid API key.
Why is there no field for my API key?
So the key never touches a web page. The generated code reads it from the DIOTP_API_KEY environment variable, which is the safe way to handle it on a server.
Which languages does it support?
cURL, PHP, Node.js and Python. The calls are plain HTTPS with JSON, so the cURL version also shows what to send from any other language.
Can I generate code for WhatsApp OTP?
Yes. Pick WhatsApp as the channel. The code works once WhatsApp is switched on for your account; until then the send returns 409 channel_not_enabled.
Does the code need DLT registration to work?
No. Your codes are sent on DiOTP's registered header and pre-approved OTP template. If you later add your own sender ID in the dashboard, the same code keeps working.
