POST /v1/messages sends free-form text or a WhatsApp template. POST /v1/calls makes a voice agent call a phone number. Both accept an Idempotency-Key: send one with every request, so that a retry after a timeout never sends or calls twice. See Idempotency.
What each channel accepts
The lead’schannel decides what you can send it:
Where the table says no, the API returns
400 recipient_invalid with param: lead_id. Instagram outside the window returns 409 messaging_window_closed.
Send text
201 with the message:
- Text goes only to a
lead_id, with up to 4096 characters. A long text can reach the lead as several messages: the response returns the first one. - Sending text cancels a reply the AI was about to send, but it does not pause the AI, which keeps answering the lead’s next messages. To take over the conversation, pause the AI.
The 24-hour window
WhatsApp and Instagram only accept free-form text within 24 hours of the lead’s last message. The lead’smessaging_window_expires_at says when the window closes. On those channels, null means the lead has not written yet, so the window is closed.
Send a template
Templates only go out on WhatsApp, and only when theirstatus is approved.
Find the template and its variables
name and language exactly as listed: the API looks the template up by both. variables says what each placeholder stands for, for example name is {{1}}. The API does not fill placeholders for you: send every value in template.components. With no WhatsApp connected, the list is empty.
Send it
A template goes to one of two recipients:- An existing WhatsApp lead, with
lead_id. - A phone number, with
text_agent_idandtoin E.164. If the agent has no lead with that phone, the send creates one and the response carrieslead_created: true.
{ "type": "image", "image": { "link": "https://example.com/flat.jpg" } }. A URL button with a variable takes a component with "type": "button", "sub_type": "url" and the button’s index. If the values do not match the template, the API returns 400 parameter_invalid with param: template.components.
Template options
These steps run after WhatsApp accepts the template. If one fails, the template has still gone out: the API returns
201, and warnings names the step that failed with pause_ai_failed, variables_failed or conversation_reset_failed. Do not send the template again. Repeat only that step, for example with pause_ai or PATCH /v1/leads/{lead_id}.
Template errors
Track delivery
The response carries the status at send time, usuallyaccepted: WhatsApp took the message. sent, delivered, read and failed arrive later. To follow a message, read it again with GET /v1/messages/{message_id}, or listen to message.failed, which fires when a message to the lead fails. No event fires for delivered or read.
When a message fails, error.code is the provider’s error code and error.category groups it, for example recipient_not_reachable.
Read messages
GET /v1/leads/{lead_id}/messages lists a lead’s messages, newest first, in pages. Internal platform notices are not included.
No route lists messages across leads. To hear about new ones, subscribe to
message.received, or poll the leads with new activity and read their messages.
Attachments
A message from the lead can carry photos, videos, audio, voice notes, documents, stickers, locations or contacts.attachments lists each one with its id, type, mime_type, file_name and file_size. A caption arrives in text; without one, text is null. A voice note or an audio carries transcription, the text of what the lead said, or null if it could not be transcribed.
message.received fires once the attachment has been processed, usually a few seconds after the message arrives.
Download an attachment
GET /v1/messages/{message_id}/attachments/{attachment_id}/file redirects (302) to the file, with a signed link that is valid for one hour and downloads it under its file_name. Request this route each time you need the file instead of storing the link.
Authorization: Bearer, as with call recordings: clients do not forward it to the file’s domain. An attachment without a stored file returns 404 resource_not_found.
Pause and resume the AI
When a person takes over a conversation, pause the AI for that lead so it stops replying:ai_paused and ai_paused_until.
- Without
duration_minutes, or with0, the pause lasts until you callresume_ai. The maximum is 525600 minutes, one year. - While the AI is paused, you can still send text and templates through the API. The voice agent cannot call the lead:
POST /v1/callsreturns409 lead_ai_paused. - Pausing a lead that is already paused keeps the pause it has, with its end, and returns the lead. Resuming a lead that is not paused also returns the lead. A pause whose time is up counts as ended.
When a lead asks not to be contacted
A lead’sdo_not_contact is true when they asked the agent to stop, or when you set it with PATCH /v1/leads/{lead_id}, for example after an opt-out in your CRM:
- The AI no longer replies to the lead, and on a call it only says the team will see it. Pending follow-ups are cancelled, and no follow-ups or appointment reminders are sent.
- Unlike a pause, it also stops you: text, templates and calls through the API return
409 lead_do_not_contact. - If the lead writes or calls again, the team gets an alert in the dashboard.
"do_not_contact": falseresumes contact, like Resume contact in the dashboard: the AI replies again and you can write and call. Follow-ups and appointment reminders stay off.- It applies to one lead. A person can have one lead per channel and agent: find them all with
GET /v1/leads?phone=and mark each one.
When the send outcome is unknown
502 send_outcome_unknown means the message may have reached the lead even though the API could not confirm it.
-
Look for the message in
GET /v1/leads/{lead_id}/messages. -
For a template sent to a phone, find the lead first:
-
Use a new key only once you know the message is not there, or that it
failed.
Calls
Before you call
These checks run before dialing. The ones about hours, the number, the plan and the contact do not create or change the lead. The balance check runs after the lead is found or created: the lead keeps the
lead values you sent, and the refused call appears in GET /v1/calls with status: rejected and end_reason: rejected_balance.
Place a call
201 with the ongoing call:
- The voice agent calls from its outbound number. The API finds the agent’s lead with that phone, or creates it, and returns its
lead_id. lead.namereplaces the lead’s name andlead.variablesare merged into its variables. Both are saved before dialing, and the agent uses them during the call. If the call then fails, the lead keeps them.- Each API key can place 5 calls per minute. Over that, the API returns
429 rate_limit_exceededwithRetry-After. Calls refused after the agent check, for example outside the agent’s hours, also count. A request repeated with the sameIdempotency-Keythat returns the stored response does not. See Rate limits.
Retry a call safely
Idempotency is stricter on calls, because a repeated call rings a person’s phone again.- If the API cannot check the
Idempotency-Key, it does not place the call and returns502 provider_unavailable. Retry with the same key. 502 send_outcome_unknownmeans the phone may be ringing.error.details.call_idcarries the call when it is known:
GET /v1/calls/{call_id}. While its status is in_progress, the phone may still be ringing: wait for it to end. Without a call_id, list the agent’s recent calls:
Follow the call
To hear about the call as it happens, register a webhook endpoint with
voice_agent_id and these events:
call.startedfires once dialing is confirmed.call.endedcarries the finalstatus,end_reason, duration and transcript.call.analyzedcarries the variables the AI extracted from the call.
GET /v1/calls/{call_id}, which includes the transcript once transcript_ready is true. GET /v1/calls lists calls without the transcript, and filters by voice_agent_id, lead_id, direction, status, started_after and started_before.
Download the recording
GET /v1/calls/{call_id}/recording redirects (302) to the audio, with a signed link that is valid for one hour. Request this route each time you need the audio instead of storing the link.
Authorization: Bearer: clients do not forward it when they follow the redirect to another domain, but they do forward x-api-key. A call without a recording returns 404 resource_not_found, and its recording_url is null. The recording can arrive shortly after call.ended.
Not available yet
- Sending images, documents or other files.
typeaccepts onlytextandtemplate; a template header can carry an image, video or document by link.
Related
Retry safely
How
Idempotency-Key works and what each response stores.Webhook events
The payload of each message and call event.
Handle errors
Every error code and when to retry.
Sync leads to a CRM
Keep a CRM up to date from lead events.