Adding OTP verification to your website or app does not need a code generator, a hashing layer, an expiry timer and a lockout system built from scratch. The Pak Sender verification API handles all of that: you make two API calls — one to start a verification and send the code, one to check the code the user types in. This guide walks through both calls, with curl and PHP samples you can adapt directly.
Before you start, you need an API key, created in the Pak Sender dashboard. Keys are shown only once, so store yours securely. All requests go to the base URL https://paksender.com/api/v1, use JSON bodies, and authenticate with Authorization: Bearer YOUR_API_KEY (or the X-API-Key header). Never put your key in browser or mobile-app code, or in a public repository — verification calls belong on your server.
How the managed verification flow works
- Start. Your server calls the start endpoint with a channel, a recipient and your app name. Pak Sender generates the code, stores it hashed, and delivers it by SMS, SIM or email. The code is never returned to you — you only get a
request_id(for examplevr_xxx), apendingstatus, the expiry in seconds and the cost. - Verify. The user types the code into your form. Your server sends the
request_idand the code to the verify endpoint, which returnsverified: trueor a specific error code.
Because the code is generated, hashed, timed and locked out server-side, you never store a plain-text code in your own database — a common source of verification bugs and security issues.
Step 1: start a verification
The start endpoint is POST /v1/verifications/start. The full URL, exactly as documented, is https://paksender.com/api/v1/v1/verifications/start. The required fields are channel (sim, sms or email) and recipient. app_name is optional (alias: brand). Other optional fields include expire_time (1–30 minutes, default 10), length (4–8 digits, default 6), template (with {code}, {app} and {minutes} placeholders), sender_id and subject for email.
curl -X POST https://paksender.com/api/v1/v1/verifications/start \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"channel": "sms",
"recipient": "+923001234567",
"app_name": "MyApp",
"expire_time": 5,
"length": 6
}'A successful response looks like this:
{
"status": "success",
"message": "Verification code sent",
"data": {
"request_id": "vr_abc123",
"status": "pending",
"expires_in": 300,
"cost": 4.30
}
}Save the request_id in the user's session or your database — you need it for the verify call. The recipient receives a message such as: "482913 is your verification code for MyApp. It is valid for 5 minutes. Do not share this code with anyone."
The same call in PHP:
<?php
$apiKey = 'YOUR_API_KEY';
$ch = curl_init('https://paksender.com/api/v1/v1/verifications/start');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
'Accept: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'channel' => 'sms',
'recipient' => '+923001234567',
'app_name' => 'MyApp',
'expire_time' => 5,
'length' => 6,
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($response['status'] === 'success') {
$_SESSION['otp_request_id'] = $response['data']['request_id'];
}Step 2: verify the code
When the user submits the code, call POST /v1/verifications/verify with the request_id and the code:
curl -X POST https://paksender.com/api/v1/v1/verifications/verify \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"request_id": "vr_abc123",
"code": "482913"
}'On success the response is:
{
"status": "success",
"message": "Code verified",
"data": { "status": "verified", "verified": true }
}Only treat the user as verified when you see verified: true. Do not rely on the HTTP status alone — always check the response body.
Handling failures: error codes
Failed verifications return a stable error_code. Branch your code on that field, not on the human-readable message, which may change.
| Error code | Meaning | What to do |
|---|---|---|
CODE_INVALID | Wrong code (response includes attempts_remaining) | Let the user retry and show how many attempts are left |
CODE_EXPIRED | The code passed its expiry time | Offer a fresh code via a new start call |
CODE_LOCKED | Locked after 5 wrong tries | Require a new verification; do not keep accepting guesses |
VERIFICATION_NOT_FOUND | Unknown or stale request_id | Start a new verification |
Other errors you may meet at the start step include INVALID_NUMBER for a malformed recipient and KYC_REQUIRED (HTTP 403) when the account's KYC is not approved for SMS and voice. The API is rate-limited to 60 requests per minute, returning HTTP 429 when exceeded — so build a short cooldown into your resend button rather than letting users hammer it.
Sending your own code instead
If your application already generates its own codes and you only need delivery, use POST /v1/verifications/send with a channel, a recipient and either a code (wrapped automatically as "<code> is your verification code for <app>…") or a full custom message, plus app_name. With this endpoint you own the code lifecycle — generation, storage, expiry and attempts — while Pak Sender handles delivery. For most new integrations the managed start-and-verify flow above is simpler and safer, because the code is hashed and never exposed.
Choosing a channel
The three verification channels have different requirements. The sms channel sends through the platform short-code gateway and needs the account's SMS permission plus approved KYC (CNIC, national ID or passport). The sim channel sends from your own phone number through the My SIM Android gateway and needs only the SIM permission — no short-code KYC. The email channel needs an active SMTP connection in your account. Short-code and SIM API calls also only work from an approved website, app or IP address, which you submit in the dashboard for admin approval. Pick the channel that matches your setup, and keep the others in mind as fallbacks.
For the complete reference — including sending plain SMS, bulk SMS and voice OTP — see the API documentation, try requests in the API tester, and read the general SMS API integration guide and the guide to adding OTP verification to your website or app.
Frequently asked questions
How many API calls does OTP verification need?
Two. POST /v1/verifications/start generates and sends the code and returns a request_id; POST /v1/verifications/verify checks the code the user enters against that request. Code generation, hashing, expiry and lockout are handled server-side.
Is the verification code ever returned by the API?
No. The code is stored hashed and never returned — the start response contains only a request_id, a pending status, expires_in and the cost. This keeps the code out of your logs and your database.
What happens after too many wrong attempts?
After 5 wrong tries the verification locks and returns CODE_LOCKED. The user needs a fresh code from a new start call. Each CODE_INVALID response includes attempts_remaining so you can show the user how many tries are left.
Can I send my own code instead of a managed one?
Yes. POST /v1/verifications/send delivers a code you generate yourself, either wrapped in the standard message or as a full custom message. You then own expiry and attempt handling; the managed flow is recommended for new integrations.