Sign-in codes by text for your own app, in two calls.
Phone Auth texts a one-time code to a Zimbabwe mobile number and tells you whether what the person typed is right. Use it to sign people in, to confirm a number at sign-up, or before something that matters (a payout, a changed password). You never make, keep or compare codes yourself.
Codes come from LocalZW until you have a sender name of your own, cost what any text costs (from 1.8¢ at the best bundle rate, one credit each) and are paid from the account's SMS credits.
curl https://api.localhost.co.zw/phone-auth/send \
-H "Authorization: Bearer $LH_PHONE_AUTH_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: signup-42" \
-d '{"phone": "0771234567", "reference": "user-42"}'
HTTP/1.1 202 Accepted
{"id": "9f1c2a…", "to": "+263771234567", "sender": "LocalZW", "expires_in": 300}
phone takes the number as people type it. app picks one of your apps (its id starts pa_); leave it out for the first. reference is yours, shown beside the code in the panel. Keep id with the person's session.
curl https://api.localhost.co.zw/phone-auth/verify \
-H "Authorization: Bearer $LH_PHONE_AUTH_KEY" \
-H "Content-Type: application/json" \
-d '{"id": "9f1c2a…", "code": "482913"}'
{"valid": true, "reason": ""}
Instead of id you may give phone: the latest code from that app to that number is checked. When valid is false, reason says why in words you can show: wrong, expired, used, too many tries, or no code sent.
| Rule | What happens |
|---|---|
| One code per number a minute | A second send within the minute answers 429. Show a "send again" button after 60 seconds. |
| Each code lasts | 5, 10, 15 minutes, set per app (5 by default). |
| 5 tries | Then the code stops working; send a new one. |
| Works once | A right code checked twice is valid: false the second time, even when both arrive together. |
| A new code | Replaces nothing: each has its own id. Checking by phone uses the newest. |
| Digits | 4, 6, 8, set per app (6 by default). |
| Out of credits | 402, and nothing is sent. Top up on the SMS page. |
| Retries | The same Idempotency-Key returns the first answer and never texts twice. |
Each app has the name the text uses (“482913 is your Gofasta code. It expires in 5 minutes. Don't share it.”), a sender, how many digits and how long a code lasts, and its own codes: a code sent by one app is never accepted by another. Add apps and change them in the panel; GET /phone-auth/apps lists them.
To send from your own name, apply for a sender name on the SMS page. Once the networks approve it, choose it for the app and every code after that comes from it.
const API = "https://api.localhost.co.zw/phone-auth";
const headers = { Authorization: `Bearer ${process.env.LH_PHONE_AUTH_KEY}`, "Content-Type": "application/json" };
export const sendCode = (phone) =>
fetch(`${API}/send`, { method: "POST", headers, body: JSON.stringify({ phone }) }).then((r) => r.json());
export const checkCode = (id, code) =>
fetch(`${API}/verify`, { method: "POST", headers, body: JSON.stringify({ id, code }) }).then((r) => r.json());
import os, httpx
API = "https://api.localhost.co.zw/phone-auth"
HEADERS = {"Authorization": f"Bearer {os.environ['LH_PHONE_AUTH_KEY']}"}
def send_code(phone: str) -> dict:
return httpx.post(f"{API}/send", json={"phone": phone}, headers=HEADERS).json()
def check_code(otp_id: str, code: str) -> bool:
return httpx.post(f"{API}/verify", json={"id": otp_id, "code": code}, headers=HEADERS).json()["valid"]
Every field of these calls is in the API reference. Assistants connected to the account can do the same with the send_phone_auth_code and check_phone_auth_code tools.