Send verification codes (OTP) on WhatsApp
To send a verification code (OTP) on WhatsApp, a business creates an authentication template, Meta's fixed format "<code> is your verification code." with a copy-code or one-tap button, and its backend sends it through the Cloud API with the code filled in twice, in the body and the button. Codes take up to 15 characters, and the optional expiry warning runs 1 to 90 minutes.
easyCoexistence connects your WhatsApp Business number to Meta's Cloud API through Coexistence and gives your backend what it needs to send authentication templates: the Send endpoint, the access token and, through your AI, create_template and get_template_status.
Longest parameter an authentication template accepts; URLs, media and emojis are not allowed in its content or parameters.
Range of code_expiration_minutes, which adds the line "This code expires in N minutes." to the message.
Default time-to-live of an authentication template; it can be set from 30 seconds to 15 minutes.
Error returned when an authentication template is sent to a business-scoped user ID instead of a phone number.
Authentication messages are delivered only to the user's primary WhatsApp device; linked devices see a prompt instead.
Fixed throughput of a Coexistence number, the ceiling for a burst of login codes.
What is a WhatsApp authentication template?
Meta's only allowed format for one-time passwords and verification codes: if an app offers codes by WhatsApp, it must use one, and utility or marketing templates cannot carry a passcode. The text is fixed, "<code> is your verification code.", with two optional lines, "For your security, do not share this code." and "This code expires in <N> minutes." What you choose is the button. WhatsApp disables forwarding of these messages, and on iOS 26 and later the code is also offered as a keyboard suggestion with no work on your side.
How do you create the authentication template?
Pick it from the Template Library in WhatsApp Manager, or submit it through the API, which your AI can do with create_template and the category AUTHENTICATION. You send no body text: Meta writes it from your settings, in the language you choose, and turns the OTP button into a URL button on creation. One template per language. The connector's create_template does not pass message_send_ttl_seconds, so the 10-minute default time-to-live applies unless you change it through Meta's API.
{
"connection_id": "<from list_numbers>",
"name": "login_code",
"language": "en_US",
"category": "AUTHENTICATION",
"components": [
{ "type": "BODY", "add_security_recommendation": true },
{ "type": "FOOTER", "code_expiration_minutes": 5 },
{ "type": "BUTTONS", "buttons": [
{ "type": "OTP", "otp_type": "COPY_CODE", "text": "Copy code" }
]}
]
}How does your backend send the code?
One request to the number's /messages endpoint per code, with the access token from get_api_credentials or the dashboard's "Plug in your own system" card. The same code goes in twice, in the body parameter and in the URL button parameter at index 0, and the recipient must be a phone number. Before sending, the backend generates the code, stores a hash of it with an expiry time and an attempt counter, and afterwards compares what the user types against that hash.
POST https://graph.facebook.com/<VERSION>/<PHONE_NUMBER_ID>/messages
Authorization: Bearer <ACCESS_TOKEN>
{
"messaging_product": "whatsapp",
"to": "5511987654321",
"type": "template",
"template": {
"name": "login_code",
"language": { "code": "en_US" },
"components": [
{ "type": "body",
"parameters": [{ "type": "text", "text": "482913" }] },
{ "type": "button", "sub_type": "url", "index": "0",
"parameters": [{ "type": "text", "text": "482913" }] }
]
}
}Why does the code come from your backend and not an automation?
Because the system that logs the user in must create the code, remember it and check it, and only that system knows when a code is needed. Automations answer messages customers send, and a login screen never writes to your number. The template itself also rules them out: the OTP button carries the code as a button variable, and the Send a template step fills body variables only, so it cannot send an authentication template. Your AI can send one through send_template, which passes button components to Meta, but that is for a test, not a login flow.
What makes a WhatsApp OTP flow secure?
Meta's best practices and the format's limits point to the same checklist. None of it needs anything beyond your backend and the Cloud API:
- Confirm the WhatsApp number with the user before the first code, and say the code will arrive on WhatsApp.
- Set the time-to-live at or under the code's expiry, so a late delivery never shows a dead code.
- Limit attempts and resends per number, and expire codes on first use.
- Do not make a WhatsApp code the only factor for account recovery: recycled phone numbers can still reach an old WhatsApp account.
- Watch the status webhook and offer SMS or email when a code fails to deliver.
What changes when the number also runs in the WhatsApp Business app?
Sending works as on any Cloud API number, up to 20 messages per second. Meta mirrors messages sent through the API into the app's chats, so on a Coexistence number the codes you send also show in those chats on the business phone; keep that phone with people you trust, or send codes from a separate number. Meta's best practices also ask each business to send authentication templates from its own number, never one shared between businesses. Authentication is a paid template category billed per delivered message by the recipient's country, with separate authentication-international rates in some markets; easyCoexistence adds no markup.
How to set it up
- Connect the numberConnect your WhatsApp Business number to easyCoexistence through Meta's Coexistence flow, or use a separate number reserved for codes.
- Create the authentication templateAsk your AI to submit login_code with create_template, category AUTHENTICATION, a copy-code button and an expiry, then check get_template_status for APPROVED.
- Store the credentials on your serverCall get_api_credentials or open "Plug in your own system" in the dashboard, and put the Send endpoint and access token in your backend's secrets.
- Build generate, send and verifyGenerate the code, store its hash with an expiry, send the template with the code in the body and button, then check the user's entry against the hash.
- Handle failuresRead failed statuses from the number's webhook, then offer SMS or email and show the user which number the code went to.
Common mistakes
- Writing the code into a utility template such as "Your code is {{1}}". Meta allows passcodes only in authentication templates and rejects utility or marketing ones it finds carrying them.
- Sending the code in the body only. The copy-code button needs the same value as its parameter; Meta expects the code twice in the request.
- Keeping a 30-day time-to-live on an older authentication template. A phone offline for an hour then receives an expired code; set it at or under the code's expiry.
- Addressing the code to a business-scoped user ID. Authentication templates go to phone numbers only, and Meta returns error 131062.
The number is monitored 24/7, so a disconnection that would stop login codes reaches you by email. US$ 9 down to US$ 0.75 per number per month, falling as you add numbers, with the first 3 days free.
easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.
Frequently asked questions
Is a WhatsApp OTP cheaper than an SMS code?
It depends on the country. Meta charges each delivered authentication message at its rate for the recipient's country, with special rates in some markets, and SMS prices vary by carrier and route. Compare Meta's rate card with your SMS provider's for your main countries before switching.
Is this the same as WhatsApp's two-step verification PIN?
No. Two-step verification is the six-digit PIN that protects the business's own WhatsApp number. An authentication template sends a code to your customers so your app or site can confirm who they are.
Do users have to opt in to receive codes?
Yes. Meta's policy requires permission before a business messages someone, and its OTP guidance suggests offering a choice of channels, such as WhatsApp, SMS or email. Choosing WhatsApp on your login screen, next to the number, is that permission.
Can an agency send codes for several clients from one number?
No. Meta's best practices require each business to have its own WhatsApp Business Account and phone number for authentication templates; sharing one between businesses is against Meta's terms and policy. Connect a number per client instead.
Keep reading
Ready to get started?
Set up WhatsApp Coexistence in minutes, not months. The app keeps working on the phone.
Start Free TrialVerified on