Integration guide
Base URL https://otpapi.vault-of-wisdom.com · every request needs
Authorization: Bearer <tenant key>.
Quick start
curl -sS -X POST https://otpapi.vault-of-wisdom.com/v1/otp/request \
-H "Authorization: Bearer <your tenant key>" \
-H "Content-Type: application/json" \
-d '{"phone":"+265991234567","purpose":"login"}'
curl -sS -X POST https://otpapi.vault-of-wisdom.com/v1/otp/verify \
-H "Authorization: Bearer <your tenant key>" \
-H "Content-Type: application/json" \
-d '{"request_id":"<request_id from the call above>","code":"123456"}'
"""pip install requests"""
import requests
API = "https://otpapi.vault-of-wisdom.com"
KEY = "<your tenant key>"
HEADERS = {"Authorization": f"Bearer {KEY}"}
def send_otp(phone: str) -> str:
r = requests.post(f"{API}/v1/otp/request", headers=HEADERS,
json={"phone": phone, "purpose": "login"}, timeout=15)
r.raise_for_status()
return r.json()["request_id"]
def verify_otp(request_id: str, code: str) -> bool:
r = requests.post(f"{API}/v1/otp/verify", headers=HEADERS,
json={"request_id": request_id, "code": code}, timeout=15)
return r.status_code == 200 and r.json().get("valid") is True
if __name__ == "__main__":
rid = send_otp("+265991234567")
print("sent:", rid) # user receives the SMS
# print(verify_otp(rid, input("code: ")))
// Node 18+ (global fetch)
const API = "https://otpapi.vault-of-wisdom.com";
const KEY = "<your tenant key>";
const headers = { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" };
async function sendOtp(phone) {
const res = await fetch(`${API}/v1/otp/request`, {
method: "POST",
headers,
body: JSON.stringify({ phone, purpose: "login" }),
});
if (!res.ok) throw new Error(`send failed: ${res.status} ${await res.text()}`);
return (await res.json()).request_id;
}
async function verifyOtp(requestId, code) {
const res = await fetch(`${API}/v1/otp/verify`, {
method: "POST",
headers,
body: JSON.stringify({ request_id: requestId, code }),
});
const body = await res.json();
return res.ok && body.valid === true;
}
// sendOtp("+265991234567").then(console.log);
<?php
$API = "https://otpapi.vault-of-wisdom.com";
$KEY = "<your tenant key>";
function otp_post(string $path, array $payload): array {
global $API, $KEY;
$ch = curl_init($API . $path);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $KEY", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$raw = curl_exec($ch);
if ($raw === false) { throw new RuntimeException(curl_error($ch)); }
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$status, json_decode($raw, true)];
}
[$status, $body] = otp_post("/v1/otp/request", ["phone" => "+265991234567", "purpose" => "login"]);
echo $status === 200 ? "request_id: " . $body["request_id"] . PHP_EOL : "error: " . $status . PHP_EOL;
Integrating your app with the OTP gateway
Short version: your server calls two endpoints — one to queue a code, one to check it. The tenant key never leaves your backend. The phone-side app is already handled; you do not touch it.
your backend ──POST /v1/otp/request──► gateway ──► phone sends SMS ──► your user
your backend ◄──── { request_id } ─────┘
user types code
your backend ──POST /v1/otp/verify───► gateway ──► {"valid":true|false,...}
1. Credentials and connectivity
Ask the gateway operator (whoever runs /opt/smsgw) for:
| Item | Value |
|---|---|
| Base URL | https://otpapi.vault-of-wisdom.com |
| Tenant key | tenant_9xQ… (shown once, store as a secret) |
| Interactive docs | https://otpapi.vault-of-wisdom.com/docs |
| Portal (signup, billing, your key) | https://smsgw.vault-of-wisdom.com |
The endpoint is served under a normal publicly trusted certificate
(Let's Encrypt), so there is nothing to install or configure: fetch,
requests, curl, Postman and HTTP client libraries all work with default
settings.
curl -s https://otpapi.vault-of-wisdom.com/openapi.json | head -c 80
# {"openapi":"3.1.0","info":{"title":"SMS OTP Gateway"…
The older
https://185.131.54.4:8443endpoint still answers — same gateway, but with Caddy's internal CA and a raw IP. It exists for the phone app and direct operator access; do not build against it (the IP can change, and it needs-kor a CA bundle). Everything here uses the domain.
Keys are issued by the portal: sign up at https://smsgw.vault-of-wisdom.com/signup,
pay the invoice, and the dashboard shows your tenant key together with this guide
pre-filled with that key and a panel that sends a real test OTP.
The tenant key belongs on a server only: it lets whoever holds it send SMS on your account, so it must never reach a browser or a mobile app.
2. The two calls
Queue a code
curl -X POST https://otpapi.vault-of-wisdom.com/v1/otp/request \
-H "Authorization: Bearer <your tenant key>" \
-H 'Content-Type: application/json' \
-d '{"phone":"+265991234567"}'
# 200 {"request_id":"c1b2…","expires_in":300,"status":"queued"}
phone must be E.164 (+ and country code, 7–15 digits). purpose is an optional
≤64-char label ("signup", "password_reset"). One request per phone per
60 seconds per tenant — a second one returns 429.
Check a code
curl -X POST https://otpapi.vault-of-wisdom.com/v1/otp/verify \
-H "Authorization: Bearer <your tenant key>" \
-H 'Content-Type: application/json' \
-d '{"request_id":"c1b2…","code":"483920"}'
| Status | Body | Meaning | What to show the user |
|---|---|---|---|
200 |
{"valid":true} |
code was correct (now single-use) | log them in |
400 |
{"valid":false,"reason":"wrong_code"} |
not the code | "That code doesn't match" (keep the form) |
403 |
… "locked" |
5 wrong attempts | "Too many attempts, request a new code" |
409 |
… "already_used" |
already verified | "That code was already used" |
410 |
… "expired" |
older than 5 minutes | "Code expired, resend" |
404 |
{"detail":"otp request not found"} |
unknown id, or another tenant's | "Request a new code" |
Treat everything except 200 as "not verified"; the reasons are for UI copy and
logging, never for deciding that the user is legitimate.
3. Node.js client (Node 18+, no dependencies)
// otp-client.js — server-side only
const BASE = process.env.OTP_BASE_URL || 'https://otpapi.vault-of-wisdom.com';
const KEY = process.env.OTP_TENANT_KEY;
async function call(path, { method = 'POST', body } = {}) {
const res = await fetch(BASE + path, {
method,
headers: {
Authorization: `Bearer ${KEY}`,
...(body ? { 'Content-Type': 'application/json' } : {}),
},
body: body ? JSON.stringify(body) : undefined,
signal: AbortSignal.timeout(15000),
});
const text = await res.text();
let json = null;
try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON error page */ }
return { status: res.status, json };
}
export async function requestOtp(phone, purpose = 'password_reset') {
const { status, json } = await call('/v1/otp/request', { body: { phone, purpose } });
if (status === 200) return { ok: true, requestId: json.request_id, expiresIn: json.expires_in };
if (status === 429) return { ok: false, reason: 'rate_limited' };
if (status === 422) return { ok: false, reason: 'bad_phone' };
if (status === 401 || status === 403) return { ok: false, reason: 'gateway_auth' };
return { ok: false, reason: 'gateway_error', status };
}
export async function verifyOtp(requestId, code) {
const { status, json } = await call('/v1/otp/verify', {
body: { request_id: requestId, code },
});
if (status === 200 && json?.valid === true) return { valid: true };
const reason = {
400: 'wrong_code',
403: 'locked',
409: 'already_used',
410: 'expired',
404: 'not_found',
}[status] || 'gateway_error';
return { valid: false, reason };
}
// Optional: "is the SMS out yet?" — sms_status: queued | claimed | sent | failed
export async function deliveryStatus(requestId) {
const { status, json } = await call(`/v1/status/${encodeURIComponent(requestId)}`, { method: 'GET' });
return status === 200 ? json : null;
}
Wire it into your existing auth flow (Express shown; req.session can be any
server-side store — the request_id must not be sent to the browser):
import { requestOtp, verifyOtp } from './otp-client.js';
// best-effort normalisation; the gateway validates E.164 and answers 422 otherwise
function toE164(input, defaultCountry = '265') {
const digits = String(input).replace(/[^\d+]/g, '');
if (digits.startsWith('+')) return digits;
if (digits.startsWith('00')) return '+' + digits.slice(2);
if (digits.startsWith('0')) return '+' + defaultCountry + digits.slice(1);
return '+' + digits;
}
app.post('/auth/request-code', async (req, res) => {
const phone = toE164(req.body.phone);
const r = await requestOtp(phone, 'login');
if (!r.ok) {
const msg = r.reason === 'rate_limited' ? 'Wait a minute before retrying.'
: r.reason === 'bad_phone' ? 'Enter a valid international number.'
: 'Could not send the code.';
return res.status(400).json({ error: msg });
}
req.session.otp = { requestId: r.requestId, phone, at: Date.now() };
res.json({ sent: true, expiresIn: r.expiresIn });
});
app.post('/auth/verify-code', async (req, res) => {
const pending = req.session.otp;
if (!pending) return res.status(400).json({ error: 'Request a code first.' });
const r = await verifyOtp(pending.requestId, String(req.body.code || '').trim());
if (!r.valid) return res.status(400).json({ error: r.reason });
delete req.session.otp;
// issue your own session/token here, e.g. req.session.userId = user.id;
res.json({ ok: true });
});
4. Python client
import os
import requests
BASE = os.environ.get("OTP_BASE_URL", "https://otpapi.vault-of-wisdom.com")
KEY = os.environ["OTP_TENANT_KEY"]
session = requests.Session()
session.headers["Authorization"] = f"Bearer {KEY}"
def request_otp(phone: str, purpose: str = "password_reset") -> str:
"""Queue a code and return the request_id (keep it server-side)."""
r = session.post(f"{BASE}/v1/otp/request",
json={"phone": phone, "purpose": purpose}, timeout=15)
if r.status_code == 200:
return r.json()["request_id"]
if r.status_code == 429:
raise RuntimeError("rate_limited")
r.raise_for_status() # 401/403/422 are configuration or input bugs
def verify_otp(request_id: str, code: str) -> bool:
"""True only when the gateway confirms the code."""
r = session.post(f"{BASE}/v1/otp/verify",
json={"request_id": request_id, "code": code}, timeout=15)
if r.status_code == 200:
return r.json().get("valid") is True
if r.status_code in (400, 403, 404, 409, 410):
return False # wrong / locked / unknown / used / expired
r.raise_for_status()
5. Rules that avoid support tickets
- Call from the server. The tenant key in a browser means anyone can drain your SMS credit.
- Keep
request_idin your session, not in a hidden form field — otherwise a user can swap in someone else's id (the gateway still enforces the tenant, but not that the code was meant for this user). - One code per phone per minute. Disable the "resend" button for 60 s; a
second request returns
429and the first code stays valid. - Never retry
/v1/otp/requestautomatically on timeout — the job may already be queued and a retry just burns the rate limit. Ask the user to press resend. - Codes are single-use. After
200, discard therequest_id; a replay gets409. Also discard it after410so a stale id cannot linger in the session. - Delivery takes a few seconds, up to ~10–20 s: the phone polls every 10 s.
Do not tell the user "SMS failed" immediately;
GET /v1/status/{request_id}returnssms_status(queued→claimed→sent|failed) if you want a "still sending…" hint. There are no webhooks — polling is the only signal. 403 lockedarrives after 5 wrong codes; force a new request instead of letting the user keep guessing.- Log the reason, not the code.
reasonstrings (wrong_code,expired, …) are safe for logs; the six digits are not.
6. Smoke test
export OTP_BASE_URL=https://otpapi.vault-of-wisdom.com
export OTP_TENANT_KEY=tenant_… # from the operator
# 1. queue (use a phone you control)
curl -s -X POST "$OTP_BASE_URL/v1/otp/request" \
-H "Authorization: Bearer <your tenant key>" -H 'Content-Type: application/json' \
-d '{"phone":"+265991234567","purpose":"smoke_test"}'
# 2. paste the request_id from step 1
curl -s "$OTP_BASE_URL/v1/status/$REQUEST_ID" \
-H "Authorization: Bearer <your tenant key>"
Expected: {"request_id":"…","expires_in":300,"status":"queued"}, then a status
body with sms_status: queued until a paired phone picks it up.