Docs & Guides
Claywire API.
Send WhatsApp one-time codes during login or signup, and send your approved templates from your own web app, SaaS or backend. Messages go out from your connected WhatsApp number and are billed to your Claywire workspace.
Last updated: 16 November 2026
Build it with Claude Code, Cursor or Codex
The full spec is available as plain Markdown at /docs/api.md (also at /llms.txt). Open your app in an AI coding agent and paste this prompt. Put your key in the CLAYWIRE_API_KEY environment variable first.
Integrate WhatsApp OTP login using the Claywire API.
Read the spec at https://www.claywire.in/docs/api.md first and follow it exactly.
- Server side only. Read the key from the env var CLAYWIRE_API_KEY; never send it to the browser or commit it.
- Add two backend endpoints to this app: one that calls POST /otp/send with the user's phone (E.164, with country code) and stores the returned id in the user's session, and one that calls POST /otp/verify with that id and the code the user typed.
- Only log the user in when verify returns {"verified": true}. Show a clear message for each "reason" and for 429 (use Retry-After).
- Add a phone input step and a 6-digit code input step to the existing login/signup UI, matching its current styling.
- Write tests that mock the Claywire API.Before you start
- Your WhatsApp number is connected and your Claywire account is approved for live messaging.
- For OTP: an approved OTP template. Create it in Settings → Templates → OTP template. Meta usually approves within minutes.
- For messages: an approved template with a text header or no header. Media-header templates can't be sent through the API yet.
- An API key from Settings → Developers. Pick the permissions it needs: otp, messages, or both.
Authentication
Send the key in the Authorization header on every request: Bearer cw_live_…. The key is shown once when you create it. Claywire stores only a hash, so a lost key can't be recovered: revoke it and create another. Keep keys on your server. Anyone holding one can send messages billed to your workspace.
Phone numbers must include the country code, like +919876543210. Spaces and dashes are fine.
WhatsApp OTP
Claywire generates the code, sends it with your OTP template and keeps only a hash of it. Your app never sees or stores the code. It keeps the returned id(in the user's session, for example) and passes it back to verify.
Send a code: POST /api/v1/otp/send
curl https://www.claywire.in/api/v1/otp/send \
-H "Authorization: Bearer $CLAYWIRE_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"to": "+919876543210"}'
# 201 Created
{ "id": "8f1c2b3a-…", "expiresAt": "2026-11-16T12:05:00.000Z" }- to(required): the user's WhatsApp number.
- codeLength: 4 to 8 digits. Default 6.
- ttlSeconds: 60 to 900. Default 300. Match it to the expiry shown in your template.
- template, language: pick a specific OTP template when you have several. Otherwise the oldest approved one is used.
Verify a code: POST /api/v1/otp/verify
curl https://www.claywire.in/api/v1/otp/verify \
-H "Authorization: Bearer $CLAYWIRE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"id": "8f1c2b3a-…", "code": "482913"}'
# 200 OK
{ "verified": true }
# or
{ "verified": false, "reason": "invalid_code" }A well-formed request always returns 200, so you only branch on verified. When it's false, reason is one of invalid_code, expired, too_many_attempts, already_used or not_found. Each code allows 5 attempts and works once.
Node.js example
// Server-side only. Never ship the key to a browser or mobile app.
const API = "https://www.claywire.in/api/v1";
const headers = {
Authorization: `Bearer ${process.env.CLAYWIRE_API_KEY}`,
"Content-Type": "application/json",
};
export async function sendLoginCode(phone) {
const res = await fetch(`${API}/otp/send`, {
method: "POST", headers, body: JSON.stringify({ to: phone }),
});
if (!res.ok) throw new Error((await res.json()).error.message);
return (await res.json()).id; // keep this in the user's session
}
export async function checkLoginCode(id, code) {
const res = await fetch(`${API}/otp/verify`, {
method: "POST", headers, body: JSON.stringify({ id, code }),
});
const body = await res.json();
return res.ok && body.verified === true;
}Limits
- One code per number every 30 seconds, and at most 5 per number in 10 minutes.
- 60 sends per minute per API key.
- Over a limit you get 429 with a Retry-After header in seconds.
Template messages
One message: POST /api/v1/messages/template
curl https://www.claywire.in/api/v1/messages/template \
-H "Authorization: Bearer $CLAYWIRE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"to": "+919876543210", "template": "order_shipped",
"variables": {"1": "Asha", "2": "#4821"}}'
# 201 Created
{ "id": "wamid.HBgM…", "status": "sent" }variables fill the template's {{1}}, {{2}} placeholders, keyed by number. Every placeholder needs a value.
Bulk: POST /api/v1/messages/template/bulk
curl https://www.claywire.in/api/v1/messages/template/bulk \
-H "Authorization: Bearer $CLAYWIRE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"template": "order_shipped", "recipients": [
{"to": "+919876543210", "variables": {"1": "Asha", "2": "#4821"}},
{"to": "+919812345678", "variables": {"1": "Ravi", "2": "#4822"}}
]}'
# 200 OK
{ "sent": 2, "failed": 0, "skipped": 0,
"results": [ { "to": "+919876543210", "status": "sent", "id": "wamid…" }, … ] }Up to 100 recipients per request, each with its own variables. Every recipient gets a result in the same order you sent them. Invalid, duplicate and opted-out numbers are skipped. If your balance runs out partway, the rest are failed with insufficient_balance. For campaigns to thousands of contacts, use Broadcasts in the dashboard, which queue, pace and report for you.
Customers who replied STOP (opted out) are never messaged, through the API or anywhere else in Claywire. Marketing templates should only go to people who agreed to hear from you.
Safe retries
Send an Idempotency-Key header with a fresh UUID for each logical send on /otp/send, /messages/template and /messages/template/bulk. If the request times out, retry it with the same key. Claywire returns the first response, marked Idempotent-Replayed: true, and doesn't send the message again. Keys belong to your API key and last 24 hours. If a request failed before anything was sent (a 429, or a 5xx such as a credit check), retrying with the same key runs it again. A failure after sending began is stored as final, so a retry can never send twice. Use a new key for a genuinely new send.
Billing
Each message sent uses 1 Claywire credit, plus Meta's per-message charge for its category (authentication, utility or marketing) when your workspace uses a separate WhatsApp wallet. A send that WhatsApp refuses is not charged. See billing and credits.
Errors
Errors use one shape:
{ "error": { "code": "rate_limited", "message": "Wait 24s before sending another code to this number." } }- 400 invalid_request: the body is malformed or a field is invalid.
- 401 unauthorized: the key is missing, invalid or revoked.
- 402 insufficient_balance: top up credits or your WhatsApp wallet.
- 403 forbidden: the key lacks the permission, WhatsApp isn't connected, or the number opted out. workspace_not_live: the account isn't approved yet.
- 404 not_found: no template with that name.
- 409 template_not_approved: the template isn't approved by Meta. idempotency_in_progress: a request with the same Idempotency-Key is still running.
- 422 idempotency_key_reused: that Idempotency-Key was used for a different request.
- 429 rate_limited: slow down, see Retry-After.
- 502 provider_error: WhatsApp refused the message. The message says why.
Webhooks
Add an endpoint in Settings → Developers → Webhooks to receive events on your server. You get a signing secret (whsec_…) once.
- message.status: a message you sent with this API was sent, delivered, read or failed.
- message.received: a customer messaged your WhatsApp number.
POST https://your-app.com/webhooks/claywire
Claywire-Signature: t=1763632805,v1=5f2c…
{ "id": "6f1c2b3a-…", "type": "message.status", "created_at": "2026-11-20T10:00:05.000Z",
"data": { "message_id": "wamid.HBgM…", "status": "read", "to": "919876543210",
"kind": "otp", "timestamp": "2026-11-20T10:00:04.000Z" } }Before trusting a request, check its Claywire-Signature header. It has the form t=<unix seconds>,v1=<hex HMAC-SHA256>, signed over <t>.<raw body>. Reject anything more than 5 minutes old.
import { createHmac, timingSafeEqual } from "node:crypto";
// Use the RAW request body, before any JSON parsing.
export function verifyClaywire(rawBody, header, secret) {
if (!header) return false;
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const t = Number(parts.t);
if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > 300) return false;
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
const given = Buffer.from(parts.v1 ?? "", "hex");
return given.length === expected.length && timingSafeEqual(given, expected);
}Answer with a 2xx status within 10 seconds, then do your own processing. Failed deliveries are retried with backoff, 6 attempts in total. The same event can arrive more than once or out of order, so deduplicate on id. Recent deliveries and their results are listed under the endpoint in Settings.
Not available yet
SMS fallback and media-header templates are not part of the API yet. Email team@claywire.in if you need one of them.

