One-time codes
Send a 6-digit code by SMS or WhatsApp, then check what the person typed.
Three calls: send a code, send it again, check it. Ghala makes the code, sends it and checks it, so your server never stores one.
Send
curl https://v3.ghala.io/v1/otp \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: signin-0700000001-1" \
-d '{"identifier": "0700000001", "channels": ["sms"], "purpose": "login"}'/v1/otpSend OTPotp:send
| Field | ||
|---|---|---|
identifier | required | the phone number |
channels | required | one or two of whatsapp and sms, no repeats |
purpose | default | up to 32 of a-z, 0-9 and _ |
ttl_seconds | 300 | 60 to 480 |
sender_id | your first approved one | for SMS |
app_name | your workspace's name | up to 20 letters, digits and spaces; the SMS says it |
language | en | en or sw |
{
"otp_id": "01a2234c-9edf-7965-a3d4-c65a70aeda53",
"expires_at": "2026-11-28T18:00:53.685841Z",
"channels": [{ "channel": "sms", "status": "queued" }]
}- Each channel gets its own code, so a check can tell which one the person used. Each is charged as one message.
- A channel's
statusissent,queuedwhen the code had not left after 3 seconds,unknownwhen the network may have taken it without saying, orrefusedwith acodeandreason. A refused channel costs nothing. - SMS goes under your approved sender ID, with fixed text: "Your Acme code is 482193. It expires in 5 minutes. Do not share it."
- WhatsApp goes from your own number when it has an approved authentication template, else from Ghala's number.
- A new code to the same number and
purposeends the open one.
Send again
curl https://v3.ghala.io/v1/otp/resend \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-d '{"identifier": "0700000001", "purpose": "login"}'/v1/otp/resendResend OTPotp:send
New codes go out on the open request's channels. Its otp_id, expiry and attempts left stay the same. With no open code the answer is 404 not_found.
Check
curl https://v3.ghala.io/v1/otp/verify \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-d '{"otp_id": "01a2234c-9edf-7965-a3d4-c65a70aeda53", "code": "482193"}'/v1/otp/verifyVerify OTPotp:verify
{
"otp_id": "0193...",
"verified": true,
"purpose": "login",
"identifier": "+255712***678",
"channel": "whatsapp",
"verified_at": "2026-11-26T09:15:41Z"
}- Give
otp_id, oridentifierwith the samepurposethe code was sent with. - A code verifies once. A wrong, expired, used or unknown code answers the same
422 invalid_code, withattempts_leftwhile the code is open. Five wrong codes end it.
{
"code": "invalid_code",
"message": "That code is not right, or it has expired.",
"error": { "type": "invalid", "code": "invalid_code", "retryable": false },
"attempts_left": 4
}Keys for codes
otp:send sends and resends; otp:verify checks and spends nothing. Neither gives messages:send. A key with only these can send codes and nothing else, which is what your sign-in page should hold.
Test mode
- A test key's codes go to the sandbox, cost nothing, and only a test key can check them.
- They go out only once your workspace has sent a code with a live key. Before that, they are accepted and stay
queued. - No answer, event or message history ever shows a code. In test mode nobody receives it either, so a test key can check the
invalid_codeanswer and itsattempts_left, but not a right code.
Limits
One channel resends 30 seconds apart at the earliest (429 resend_too_soon). One number gets 5 codes an hour and 10 a day (429 too_many_codes). One key sends 300 codes an hour and 2,000 a day, and your workspace has its plan's caps (429 otp_limit_reached). Each 429 carries Retry-After.