SMS ₹0.30 · Email ₹0.05

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.

EndpointPOST https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries
AuthX-API-Key / X-API-Secret
Price₹0.30 / SMS · ₹0.05 / email
Step 1

Setup (once per app)

  1. 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).
  2. 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.reviewed event.
  3. Create an S2S key in Profile → API keys (POST /api/v1/session/keys, pick a long ttl_seconds). The secret is shown once. See the S2S guide.
  4. 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:

What the recipient sees
Your <App name> login code is 123456. It expires in 10 minutes. Do not share it with anyone. From niyantha.in
Step 2

Send an OTP

POST
https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries

Bill and send one OTP. Your backend generates and verifies the code; Niyantha only delivers it.

Request
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"
}
Email request (same endpoint, server-side only)
{
  "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.

Standard email preview (synthetic)
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.

Contract

Response & statuses

201 Created — accepted by the gateway
{
  "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"
}
Email receipt - SMTP accepted, NOT inbox delivered
{
  "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.

Later, after the operator's delivery report (GET …/deliveries/1203 or the otp.delivery.updated event)
{
  "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

CodeErrorMeaning
201CreatedThe OTP was accepted by the provider; you are billed.
200OKSame reference seen before: the earlier delivery is returned, nothing is sent or billed.
400ValidationError / NotFound / ForbiddenBad payload, unknown app name, or app name not approved yet.
402PaymentRequiredOTP delivery credit + wallet balance cannot cover one OTP. Top up at niyantha.in.
409ConflictChanged replay binding or recipient has an unresolved receipt. Do not create a new reference to bypass pending acceptance.
429RateLimitErrorMore than 5 OTPs to the same recipient within 10 minutes.
502ProviderErrorKnown refusal: failed receipt; original credit/cash charge reversed exactly once.
503OutcomeUncertainAcceptance 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" }.

S2S + dashboard

Read deliveries and app names

GET
https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries?page=1&count=20&channel=email&status=sent&app_id=&email=recipient%40example.invalid

Newest first; { items, total_count, page, count, has_more }. count <= 100. channel accepts sms/email/all; email is an exact normalized address, not a substring.

GET
https://api.niyantha.in/api/v1/s2s/accounts/otp/deliveries/:id

One delivery with its timeline and charge split.

GET
https://api.niyantha.in/api/v1/s2s/accounts/otp/apps

Your 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:

EVENT
otp.app.reviewed

{ app, account_id } after an admin approves, rejects or suspends an app name.

EVENT
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.

SMS 30p / email 5p

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 402 if the two together cannot cover the channel price (SMS 30 paise, email 5 paise).
  • Each SMS delivery links to its ledger row (transaction_id, type consume_sms_otp) in the wallet's transaction history; refunds are refund_sms_otp.
  • Email costs 5 paise per SMTP-accepted message; SMTP refusal reverses the charge. Email ledger types are consume_email_otp and refund_email_otp. Acceptance is not proof of inbox delivery.
  • Canonical wallet fields: otp_credit_paise / otp_credit_rupees. Legacy sms_credit_paise / sms_credit_rupees alias the same bucket: never add them together, and use nullish fallback so canonical zero wins. Ledger otp_credit_change / otp_credit_before / otp_credit_after has the same alias rule. Historical SMS rows remain SMS-labelled within OTP delivery credit semantics.
  • Separate map_credit_paise / map_credit_rupees pays 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 add from_credit_paise / from_balance_paise funding splits; refund returns each source. Ledger types: consume_location_search, refund_location_search, grant_map_credit.
  • Credit grants use canonical /accounts/:account_id/otp-credit or legacy /sms-credit under either admin role prefix; both produce grant_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_rupees excludes restricted credit. Direction/category filters count OTP/SMS once; category=otp and category=sms alias, category=map is 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.
Samples

Copy-paste integrations

Go
// 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
Node (fetch)
// 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
Python (requests)
# 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 wallet
curl
curl -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"}'