OTP Delivery API
Deliver login codes from your backend by SMS or standard email. Register one app name for both channels, make one S2S call per OTP, and read receipts. Email sent means SMTP accepted, not confirmed inbox delivery.
POST https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveriesX-API-Key / X-API-Secret₹0.30 / SMS · ₹0.05 / emailSetup (once per app)
- Sign in to niyantha.in (your product's admin signs up with a mobile number; the same account owns the wallet, the keys and the deliveries).
- Open the OTP delivery tab and register your app name as it should appear in SMS/email (2–30 characters). A Niyantha admin reviews it; you see the result in the tab and receive a realtime
otp.app.reviewedevent. - Create an S2S key in Profile → API keys (
POST /api/v1/session/keys, pick a longttl_seconds). The secret is shown once. See the S2S guide. - Fund the wallet (or ask Niyantha for OTP delivery credit). SMS costs 30 paise; email costs 5 paise. Both spend the same OTP delivery credit before cash. One account/name approval covers both channels, with no separate email review.
The SMS text is fixed by the operator-registered template; only your app name and the code change:
Your <App name> login code is 123456. It expires in 10 minutes. Do not share it with anyone. From niyantha.inSend an OTP
https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveriesBill and send one OTP. Your backend generates and verifies the code; Niyantha only delivers it.
POST /api/v1/s2s/accounts/otp/deliveries HTTP/1.1
Host: api.niyantha.in
Content-Type: application/json
X-API-Key: <public key>
X-API-Secret: <secret>
{
"app_name": "Example App",
"otp": "123456",
"contact": "+91 90000 00000",
"reference": "login-10293"
}{
"channel": "email",
"email": "recipient@example.com",
"app_name": "Example App",
"otp": "123456",
"reference": "example-email-challenge-001",
"validity_seconds": 300
}Email uses Niyantha's fixed subject ("Your verification code"), standard body and default sender. Only app name, code and recipient vary; no caller HTML, sender override, CC or BCC. Default validity is 600 seconds; the issuer owns expiry/verification and must pass its actual shorter validity (email allows 60-1800 seconds). Never send API secrets from a browser, expose codes in logs, or execute these synthetic examples against real recipients.
Subject: Your verification code
Your Example App verification code is 123456. It expires in 600 seconds. Do not share it with anyone.app_namestring, requiredAn app name you registered that an admin approved. Case/spacing-insensitive match.otpstring, requiredThe code you generated: 4–10 letters or digits. Niyantha never stores it.channelstring, optionalsms (default when omitted) or email. Existing SMS payloads still work.emailstring for emailOne bare email address; required for channel=email. No display name, list, CC or BCC.contactstring for SMSIndian mobile: 10 digits starting 6–9, with or without +91 / 91 / 0. Stored as +91XXXXXXXXXX.validity_secondsinteger, optionalOmitted/0 means 600. Email permits 60-1800 seconds; pass the issuer's actual shorter expiry. SMS requires 600.referencestring, optionalAccount-wide idempotency key (<=120 chars). Exact app/channel/recipient/validity replay returns the earlier receipt; changed binding returns 409.Always send a reference (for example your own OTP/challenge id). A timeout or 503 may mean the message was accepted. Keep the original receipt/reference and poll or seek reconciliation; do not automatically resend or switch to a new reference. A safe exact-binding replay returns the original receipt without sending again.
Response & statuses
{
"id": 1203,
"app_id": 4,
"app_name": "Example App",
"contact": "+919000000000",
"otp_length": 6,
"reference": "login-10293",
"status": "sent",
"provider": "msg91",
"provider_request_id": "3763646c3058373530393938",
"requested_at": 1791273000,
"sent_at": 1791273000,
"provider_latency_ms": 238,
"price_paise": 30,
"charged_paise": 30,
"from_credit_paise": 30,
"from_balance_paise": 0,
"transaction_id": 88211,
"api_key_id": 17,
"api_key_name": "example-server-key"
}{
"id": 1204, "channel": "email", "email": "recipient@example.com",
"app_name": "Example App", "otp_length": 6, "validity_seconds": 300,
"status": "sent", "delivery": "provider_accepted", "provider": "smtp",
"price_paise": 5, "charged_paise": 5, "from_credit_paise": 5, "from_balance_paise": 0
}Channel/email fields are additive; historical receipts without channel mean SMS. Email has no handset report or manufactured delivered status.
{
"id": 1203,
"status": "delivered",
"delivered_at": 1791273006,
"delivery_ms": 6000,
"provider_status_desc": "DELIVERED",
"...": "all other fields as above"
}statussending or uncertain means acceptance unresolved and debit retained. SMS: sent -> delivered | failed. Email sent means SMTP accepted only, never confirmed inbox delivery.deliveryprovider_accepted | pending | failed. This is provider acceptance, not inbox delivery; it is distinct from Hindavi challenge delivery enums.provider_latency_msHow long the provider took to accept the message.delivery_msHandset delivery time measured from your request (set with the delivery report; whole-second resolution).charged_paise / from_credit_paise / from_balance_paiseWhat was billed and from where (OTP delivery credit first, wallet balance second).refund_transaction_idPresent when the provider refused the message and the charge was reversed.failure_reasonWhy a delivery failed: a provider error, or 'operator: NDNC' style reasons from the delivery report.provider_request_idThe gateway's message id, useful when raising a ticket.HTTP status codes
| Code | Error | Meaning |
|---|---|---|
| 201 | Created | The OTP was accepted by the provider; you are billed. |
| 200 | OK | Same reference seen before: the earlier delivery is returned, nothing is sent or billed. |
| 400 | ValidationError / NotFound / Forbidden | Bad payload, unknown app name, or app name not approved yet. |
| 402 | PaymentRequired | OTP delivery credit + wallet balance cannot cover one OTP. Top up at niyantha.in. |
| 409 | Conflict | Changed replay binding or recipient has an unresolved receipt. Do not create a new reference to bypass pending acceptance. |
| 429 | RateLimitError | More than 5 OTPs to the same recipient within 10 minutes. |
| 502 | ProviderError | Known refusal: failed receipt; original credit/cash charge reversed exactly once. |
| 503 | OutcomeUncertain | Acceptance is unresolved; sending/uncertain receipt and debit retained. Keep receipt/reference, poll or reconcile; never automatically resend/refund. |
Errors are JSON: { "error": "PaymentRequired", "message": "insufficient OTP delivery credit and wallet balance for a ₹0.30 OTP; add money to your Niyantha wallet" }.
Read deliveries and app names
https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries?page=1&count=20&channel=email&status=sent&app_id=&email=recipient%40example.invalidNewest first; { items, total_count, page, count, has_more }. count <= 100. channel accepts sms/email/all; email is an exact normalized address, not a substring.
https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries/:idOne delivery with its timeline and charge split.
https://api.niyantha.in/api/v1/s2s/accounts/otp/appsYour app names with status (pending | approved | rejected | suspended) sample_preview (SMS) and email_sample_preview { subject, text, html, validity_seconds }. Render preview text as text, not caller HTML.
The dashboard's OTP delivery tab uses the same data over the realtime connection (account identity): otp.overview, otp.apps.list, otp.app.apply, otp.deliveries.list, otp.delivery.get. Two events are pushed to the account's sockets:
otp.app.reviewed{ app, account_id } after an admin approves, rejects or suspends an app name.
otp.delivery.updated{ delivery } when a delivery is sent, fails, or receives a delivery report.
Sending is deliberately S2S-only, so a browser session never needs to hold an API secret.
Pricing & billing
- Flat ₹0.30 per SMS the gateway accepts (statuses
sent,delivered, and operator-reported failures such as DND numbers). Gateway refusals (502) are reversed immediately. - Charged to the wallet's OTP delivery credit first and the rupee balance second, never partially: an OTP is refused with
402if the two together cannot cover the channel price (SMS 30 paise, email 5 paise). - Each SMS delivery links to its ledger row (
transaction_id, typeconsume_sms_otp) in the wallet's transaction history; refunds arerefund_sms_otp. - Email costs 5 paise per SMTP-accepted message; SMTP refusal reverses the charge. Email ledger types are
consume_email_otpandrefund_email_otp. Acceptance is not proof of inbox delivery. - Canonical wallet fields:
otp_credit_paise / otp_credit_rupees. Legacysms_credit_paise / sms_credit_rupeesalias the same bucket: never add them together, and use nullish fallback so canonical zero wins. Ledgerotp_credit_change / otp_credit_before / otp_credit_afterhas the same alias rule. Historical SMS rows remain SMS-labelled within OTP delivery credit semantics. - Separate
map_credit_paise / map_credit_rupeespays for metered Places autocomplete/resolution at 1 paise per successful lookup, before cash. MAP, OTP, AI and devbox credits are independent and are not cash. Location receipts retain original receipt fields and addfrom_credit_paise / from_balance_paisefunding splits; refund returns each source. Ledger types:consume_location_search,refund_location_search,grant_map_credit. - Credit grants use canonical
/accounts/:account_id/otp-creditor legacy/sms-creditunder either admin role prefix; both producegrant_sms_credit, never a new grant_otp_credit type. MAP uses/map-credit. Body:{ "amount_paise": 100, "reference": "operator note", "idempotency_key": "optional-stable-key" }. Reference is descriptive, not unique; without a key repeated grants grant again. Same bucket/key/amount returns the original transaction across SMS/OTP aliases; changed amount gives 409. MAP keys are separate. This dashboard adds no grant controls. - Cash
amount_paise / amount_rupeesexcludes restricted credit. Direction/category filters count OTP/SMS once;category=otpandcategory=smsalias,category=mapis distinct. SMS/email capacities are alternatives over the same OTP credit plus positive cash, not allocated funds. - Limits: 5 OTPs per recipient per 10 minutes per account, up to 10 app names per account. Need more? Talk to us.
Copy-paste integrations
// For email replace contact with: "channel": "email", "email": recipient
body, _ := json.Marshal(map[string]string{"app_name": "Example App", "otp": code, "contact": phone, "reference": challengeID})
req, _ := http.NewRequest(http.MethodPost, "https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", os.Getenv("NIYANTHA_KEY"))
req.Header.Set("X-API-Secret", os.Getenv("NIYANTHA_SECRET"))
resp, err := http.DefaultClient.Do(req)
// 201/200 accepted · 402 top up · 429 slow down · 502 known refusal/refund
// 503/timeout: keep original receipt/reference and poll; do NOT resend// Server-side only. Email: replace contact with channel: "email", email: recipient
const res = await fetch("https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries", {
method: "POST",
headers: { "Content-Type": "application/json", "X-API-Key": process.env.NIYANTHA_KEY, "X-API-Secret": process.env.NIYANTHA_SECRET },
body: JSON.stringify({ app_name: "Example App", otp: code, contact: phone, reference: challengeId }),
});
const delivery = await res.json(); // sent = provider accepted, NOT inbox delivery
// 503/timeout: keep original receipt/reference and poll; do NOT resend# Server-side only. Email: replace contact with "channel": "email", "email": recipient
r = requests.post("https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries",
json={"app_name": "Example App", "otp": code, "contact": phone, "reference": challenge_id},
headers={"X-API-Key": os.environ["NIYANTHA_KEY"], "X-API-Secret": os.environ["NIYANTHA_SECRET"]}, timeout=15)
r.raise_for_status() # 402 → ask the account owner to top up the Niyantha walletcurl -X POST https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries \
-H "Content-Type: application/json" -H "X-API-Key: $NIYANTHA_KEY" -H "X-API-Secret: $NIYANTHA_SECRET" \
-d '{"app_name":"Example App","otp":"123456","contact":"+919000000000","reference":"login-10293"}'