Every developer who works with OTPs hits the same wall. At first you buy numbers by hand — open the site, pick a country, copy the number, wait, copy the code, paste it in. It takes a minute. Fine. Then your tool, your bot, or your little reseller panel starts getting real users, and suddenly you are the bottleneck. A human clicking buttons does not scale, and it definitely does not work at 3 a.m. when a customer on the other side of the world wants a Telegram number right now.
That wall is exactly what an API removes. This guide walks through the OTPDesk API the way I wish someone had walked me through it: what it is, how one full activation works call by call, the two features that quietly save you money, and the mistakes that quietly cost you money. Everything here comes from the live docs at otpdesk.com/docs — no invented endpoints, no imaginary features.
One endpoint. That is the whole API.
Most APIs make you learn a small city of URLs. This one has a single address:
https://otpdesk.com/api/handler_api.php
Everything is a plain GET request (POST form bodies work too), every answer is JSON, and you choose what the endpoint does with one parameter: action. Want a number? ?action=getNumber. Want your balance? ?action=getBalance. Same door, different rooms.
Right now the API reaches 229 countries and 3,925 services across 5 live servers. Those are the counters on the docs page today, not marketing round numbers, and they move as stock changes.
Authentication is one API key from your OTPDesk account — creating the account is free, and the key is sitting in your dashboard. You can send it three ways: as an X-API-Key header, as an Authorization: Bearer header, or as an api_key query parameter. Pick the header if you can; URLs have a habit of ending up in logs. And keep the key on your server, never inside a phone app or a web page — anyone holding that key can spend your balance. That sentence is in the docs, and it deserves to be.
Every response wears the same envelope, which your future self will thank you for:
{
"success": true,
"message": "ok",
"data": { ... }
}
Failures use the same shape with success: false and a steady machine-readable error_code inside data. Hold that thought — it becomes important in the mistakes section.
Your first activation, call by call
Here is the whole life of one OTP purchase. Three calls. This is the beating heart of every panel, bot, and automation built on OTPDesk.
Call 1 — buy the number: getNumber
GET https://otpdesk.com/api/handler_api.php?action=getNumber&service=Telegram&country=India X-API-Key: <your-api-key>
Two things are required: the service name (Telegram, WhatsApp, Google — the exact names come from getServicesList) and the country name (exact names from getCountries). The answer hands you the goods:
{
"success": true,
"message": "ok",
"data": { "id": 12345, "phone": "919000000000", "price": 12.50, "server_id": 1 }
}
Save that id. Every later call about this purchase needs it. There is also a getNumberV2 twin that buys the same way but answers with more detail — activation time, country and service names, and a flag telling you whether the number can receive another SMS.
Call 2 — wait for the code: getStatus
GET https://otpdesk.com/api/handler_api.php?action=getStatus&id=12345
Poll this every few seconds. While the sender is still sending, the status sits in its waiting state. When the SMS lands, you get STATUS_OK and the extracted code. Need the full message text or the delivery time instead of just the code? That is getStatusV2. One warning from the docs, worded politely there and bluntly here: do not poll in a tight loop. Requests are rate-limited per account, and a script that asks forty times a second will meet the RATE_LIMIT error personally.
Call 3 — close it properly: setStatus
When you are done, say so. setStatus takes the activation id and one of three values:
- 6 — finished. The activation closes, no refund. Use it when the code arrived and the job is done.
- 8 — cancel. Your balance is refunded — as long as no code has arrived yet. Changed your mind, wrong country, user walked away? Cancel and take the money back.
- 3 — send me the next OTP on this same number. There is also a dedicated
regetNumbercall that does the same thing where the service supports more than one code.
That is a complete integration in three calls. Everything else in the API exists to make those three calls cheaper, smarter, or easier to run at scale.
The two features that quietly save you money
Auto-routing: let the API shop across 5 servers for you
OTPDesk numbers come from five independent upstream servers, numbered 1 to 5. Here is the part many integrators miss on their first read of the docs: if you leave server_id out of getNumber, the API shops for you. It routes across every server, cheapest first, and if the first server is out of stock it falls back to the next one on its own. Your code sees one request and one answer; the hunting happens behind the curtain.
If you do pin a server_id, the request locks to that server alone — no fallback, and a clean error if it has nothing. Pinning has its uses (you may know a certain server delivers best for a certain service), but as a default setting for a new integration, it is how people manufacture their own "no numbers" errors. Start un-pinned. Pin later, with data, on purpose.
One habit the docs push hard, and they are right: fetch the live server list with getServers when your app starts instead of hardcoding 1–5 forever. Servers get added and retired. The integrations that break at midnight are the ones with magic numbers baked in.
max_price: a ceiling your code cannot break
Prices move with stock. A route that cost 12 yesterday can cost 30 today when demand spikes, and a naive script will happily pay it a hundred times before anyone notices. getNumber and getNumberV2 both accept max_price — a hard ceiling. Cross it, and the purchase simply fails instead of overspending. Set it from your own selling price minus the margin you refuse to give up, and a bad price day becomes a few failed orders instead of a drained wallet. It is the cheapest insurance in the whole API, and it costs one parameter.
Picking winners with data instead of vibes
Ask in any seller group which country works best for WhatsApp and you will get nine opinions, four of them confident and three of them outdated. The API answers that question with numbers:
- getPrices — live prices and stock, filterable by country, service, and server. The price it quotes is the price getNumber will actually deduct, account discount included. No surprises between the catalogue and the checkout.
- getTopCountriesByService — give it a service, get its countries ranked by recent successful deliveries first, then stock, then price. Rank 1 is not an opinion; it is the route that has actually been delivering.
- getTopServicesByCountry — the mirror image: what people successfully activate in a given country.
- getServicesList and getCountries — the full catalogues (3,925 services, 229 countries at last count), merged across servers with the best price shown, or filtered to one server or country.
- getBalance and getOrders — your money and your history. getOrders pages through past activations, newest first, each tagged with the server that fulfilled it. When a customer says "my code never came", this is where the truth lives.
Panels that re-rank their country lists from getTopCountriesByService every hour quietly out-convert panels that set a list once in January and pray. The data is already there. Most people just never wire it up.
Mistakes that cost real money (all of them common)
Polling like a woodpecker. getStatus every 200 milliseconds feels responsive. It is actually a fast route to RATE_LIMIT (HTTP 429) and a throttled account at the exact moment you need it most. A few seconds between polls is what the docs ask for, and OTPs take longer than that to arrive anyway. You gain nothing by asking early and often.
Never cancelling dead activations. A user abandons checkout, your script forgets the activation, and the money sits locked. The docs say it plainly: an abandoned activation is only refunded if you cancel it. Wire setStatus with status 8 into every timeout and abandon path you have. This one habit pays for the whole integration.
Branching on the message text. The human-readable message can change wording at any time. The error_code is the contract: BAD_KEY, NO_BALANCE, NO_NUMBERS, BAD_SERVICE, BAD_COUNTRY, NO_ACTIVATION, RATE_LIMIT. Write your logic against the codes and your error handling survives every copy edit we ever make.
Shipping the API key in the app. A key inside a mobile app or a browser page is a key you have given away. Route calls through your own small backend. Ten lines of proxy code now, or a drained balance and a support ticket later — pick one.
Hardcoding server IDs and country names from memory. Names and servers come from getCountries, getServicesList, and getServers. Fetch them, cache them for a while, refresh them. The API literally hands you its own dictionary; typing names from memory is how you earn a BAD_COUNTRY at 404.
Who actually builds on this API
Reseller panels. The biggest group. A panel owner connects the API once, sets retail prices above the API's prices, and the whole shop — buy, wait, deliver, refund on cancel — runs itself. The owner's job shrinks to keeping the balance topped up and watching getOrders. That is the difference between running a store and being the store's busiest employee.
Bots. Telegram bots especially. A user taps two buttons in chat, the bot calls getNumber, polls getStatus in the background, and drops the code into the conversation when it lands. No website, no dashboard, no human in the loop at 3 a.m.
Testing and QA teams. The quiet professionals. Signup flows need OTPs, OTPs need numbers, and testing in twenty countries with twenty physical SIMs is a logistics hobby nobody wants. API numbers turn "test the German signup flow" into a line item instead of a project.
Automation scripts. Account checks, delivery verification, monitoring your own services' SMS flows — the long tail of small scripts that each save someone an hour a week and together save a salary.
Error codes worth taping to your monitor
| Code | HTTP | What it means |
|---|---|---|
| BAD_KEY | 401 | Key missing or wrong. Check the header before you check anything else. |
| NO_BALANCE | 402 | Wallet is short. Top up and retry. |
| NO_NUMBERS | 409 | That country + service is out of stock right now. Try another country — getTopCountriesByService knows which. |
| BAD_SERVICE / BAD_COUNTRY / BAD_SERVER | 404 | A name or id the API does not know. Pull the real values from the list calls. |
| NO_ACTIVATION | 404 | That id expired or belongs to another account. |
| ALREADY_FINISHED | 409 | You are poking a closed activation. It cannot change any more. |
| RATE_LIMIT | 429 | Too many requests. Slow the polling down and back off. |
Questions developers ask us
How much does API access cost?
Nothing extra. The API runs on your normal OTPDesk account and balance — you pay per number, at the same prices the site shows, with your account discount already applied. The key itself is free with the account.
Which programming languages can use it?
Anything that can make an HTTP request and read JSON — which is to say, everything. The docs show plain curl because curl is the honest common denominator. PHP, Python, Node, Go, a shell script held together with hope: if it can GET a URL, it can run this API.
Do I have to pick a server?
No, and for a first integration you should not. Leave server_id out and the API auto-routes cheapest-first with fallback across all five servers. Pin a server only when your own delivery data tells you a specific server wins for a specific job.
What happens if the OTP never arrives?
Cancel the activation with setStatus status 8. As long as no code has arrived, the price goes back to your balance. If a code did arrive, the number did its job and the activation closes as finished instead.
How fast do codes arrive?
The same speed as buying on the website — most OTPs land within 5 to 30 seconds, because it is the same stock and the same servers. Your polling interval adds a few seconds at most; poll every few seconds and you will see the code about as fast as it exists.
The whole flow in one small script
Words are nice; running code is nicer. Here is the complete buy–wait–finish cycle in plain PHP, with the money habits from this guide built in — a max_price ceiling on the purchase, polite five-second polling, a proper finish when the code lands, and a cancelling refund when it does not. It is short enough to read in one sitting and complete enough to grow into a panel later.
<?php
$key = "YOUR_API_KEY";
$base = "https://otpdesk.com/api/handler_api.php";
function api($base, $key, $params) {
$url = $base . "?" . http_build_query($params);
$ctx = stream_context_create(["http" => ["header" => "X-API-Key: $key"]]);
return json_decode(file_get_contents($url, false, $ctx), true);
}
// 1. Buy a number, with a price ceiling
$buy = api($base, $key, ["action" => "getNumber", "service" => "Telegram",
"country" => "India", "max_price" => 20]);
$id = $buy["data"]["id"];
echo "Number: " . $buy["data"]["phone"] . "\n";
// 2. Poll every 5 seconds, up to 3 minutes
for ($i = 0; $i < 36; $i++) {
sleep(5);
$st = api($base, $key, ["action" => "getStatus", "id" => $id]);
if (($st["data"]["status"] ?? "") === "STATUS_OK") {
echo "OTP: " . $st["data"]["code"] . "\n";
// 3a. Code arrived — mark it finished
api($base, $key, ["action" => "setStatus", "id" => $id, "status" => 6]);
exit;
}
}
// 3b. Nothing arrived — cancel and take the refund
api($base, $key, ["action" => "setStatus", "id" => $id, "status" => 8]);
echo "Cancelled and refunded\n";
Thirty-odd lines, and the script already behaves better than half the rushed integrations out there — because the expensive lessons (ceilings, patience, refunds) are in it from line one instead of patched in after the first bad week.
Start small, then automate the rest
Here is the honest starter path. Create the free account, copy your key, and call getBalance — a ten-second test that proves your key works. Then buy one cheap number with getNumber, poll it with getStatus, and finish it with setStatus. You now understand the entire API; the rest is polish: max_price on every purchase, cancels on every abandon, server lists fetched at startup, and error handling keyed on error_code instead of message text.
The full reference, with every parameter and response spelled out, lives at otpdesk.com/docs. Read it with your editor open. Most people who start there on a quiet afternoon have something running before dinner — and stop buying numbers by hand forever.