Recipes
Send verification codes by voice
Read a one-time code out loud with a single request — for users without SMS, landlines or as a fallback.
Some users can't receive SMS (landlines, poor coverage, accessibility). Read the code to them instead, with just to and message.
export async function sendVoiceCode(phone, code) {
const spaced = code.split("").join(" "); // "4829" → "4 8 2 9"
const res = await fetch("https://api.callhuman.es/v1/calls", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CALLHUMAN_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
to: phone,
message: `Your verification code is ${spaced}. Again, ${spaced}.`,
}),
});
if (!res.ok) throw new Error((await res.json()).error.message);
return res.json(); // { id, status: "queued" }
}CallHuman: Your verification code is 4 8 2 9. Again, 4 8 2 9.
Why it fits codes
- One attempt, no retries: a code is never read after it expired.
- No webhook needed: your login flow just waits for the user to type the code.
- Voicemail is never left, so codes don't end up stored on an answering machine.
See One-way messages for the details.