Calls on your Twilio
Base URL: https://chatsa.co/api/v1
Make and take phone calls on a business's own Twilio numbers: click-to-call for reps, inbound forwarding with voicemail and a missed-call text, and an AI that answers the phone from the business's ChatSa chatbot. The business's Twilio account carries and pays for the calls.
Being rolled out. Calls are not on yet: ask ChatSa when they will be. Until then every request answers
503 voice_disabled. AI answering is turned on separately; until then"ai_answers": trueanswers409 ai_unavailable.
Paths are under https://chatsa.co/api/v1/voice. Authenticate with an API key that has voice:call, voice:read or voice:manage, or with a partner account key (which may do everything below). Phone numbers are E.164. Rate limits per key: 60 writes and 600 reads a minute (429 rate_limited, with Retry-After). A key limited to some chatbots sees and uses only the numbers connected to one of them.
Before the first call, save the Twilio credentials and connect the number with the SMS API (POST /sms/credentials, then POST /sms/numbers/{sid}/connect, scope sms:manage). So SMS must be on as well, and the number must be able to text. Disconnecting the number there gives its calls back too.
People's calls#
POST /api/v1/voice/calls
Authorization: Bearer csa_…
{
"from_number": "+14155550123",
"to": "+14155550199",
"agent_phone": "+14155550111",
"record": true,
"detect_voicemail": false,
"idempotency_key": "job-8812-call-1"
}
Scope voice:call.
- Twilio rings
agent_phone(the rep's own phone) fromfrom_number, for up to 25 seconds. - When the rep answers they hear "Connecting you now." (with
record: true: "This call is recorded. Connecting you now."). - Twilio dials
tofor up to 30 seconds, showingfrom_numberas the caller ID. - With
record: true, the customer hears "This call is recorded." when they pick up. ChatSa always announces a recording, so two-party-consent states such as California are covered. The recording has two channels, one per side.
agent_phoneandtomust differ.detect_voicemail: trueruns Twilio's answering machine detection on the customer's leg (it fillsanswered_by; Twilio charges extra).idempotency_keyis required (1–100 ofA-Z a-z 0-9 . _ : -; theIdempotency-Keyheader works too), unique per workspace for good: the same key answers the first call again (200); with a differentto,agent_phoneorfrom_numberit answers409 idempotency_key_reused.- Quiet hours: no call before 8 am or from 9 pm at the customer's location, by the same rules as texts, except a call back within 30 minutes of the customer's own call or text.
| Answer | Meaning |
|---|---|
201 | Twilio is ringing the rep (status: "queued") |
200 | A replay of an earlier call with this key |
202 with status: "pending" | Twilio timed out: the call may be ringing; call.completed will tell. It is never started again with this key. |
400 invalid_request | A phone number is malformed, agent_phone is to, or idempotency_key is missing |
404 number_not_found | from_number isn't a connected number this key may use |
409 not_connected, needs_reconnect | Credentials missing or refused |
422 quiet_hours | With allowed_at and time_zones |
422 voice_not_supported | The number can't make calls |
422 twilio_refused | Twilio refused the call (id, status: "failed", twilio_code) |
429 twilio_rate_limited | Nothing was started: retry with the same key |
GET /calls/{id} (voice:read) reads one call (with fresh recording links); GET /calls?contact=+1… lists a customer's calls, both ways, newest first (from_number, before, limit 1–100, default 50).
Inbound calls#
PUT /api/v1/voice/numbers/PN0123…
{
"forward_to": "+14155550111",
"ring_seconds": 20,
"voicemail": true,
"voicemail_greeting": "You've reached Acme Plumbing. Leave a message after the beep.",
"missed_call_text": "Sorry we missed your call! Reply here and we'll help.",
"record_inbound": false,
"ai_answers": false,
"replace": false
}
Scope voice:manage. The number must be connected (404 number_not_connected otherwise). Fields left out keep their value; null clears forward_to, the greetings and missed_call_text.
| Field | Default | Meaning |
|---|---|---|
forward_to | none | Who rings when a customer calls (the phone shows the caller's number). Not the number itself. |
ring_seconds | 20 | 5–60 |
voicemail | true | Take a message when nobody answers: the greeting, a beep, then up to 2 minutes (# ends it) |
voicemail_greeting | "You've reached (the business). Please leave a message after the beep, and we'll call you back." | Up to 500 characters |
missed_call_text | none | Texted to the caller when nobody answers (up to 480 characters), once per call, through every SMS rule: a caller who opted out of texts gets none |
record_inbound | false | Record forwarded calls; the caller hears "This call is recorded." first |
ai_answers | false | The AI answers first (below) |
greeting | the chatbot's greeting | The AI's first words (up to 500 characters) |
chatbot_id | as connected | The chatbot whose knowledge, voice and persona answer the calls; null unties the number |
replace | false | Take the number's calls from another webhook or TwiML app (below) |
When a customer calls:
- The AI answers, when AI answering is on (below).
- Otherwise
forward_torings forring_seconds. - When nobody answers, or there is no
forward_to: the missed-call text goes out, then voicemail takes a message. With voicemail off, the caller hears that no one is available.
ChatSa takes the number's calls only while forward_to, ai_answers or voicemail is on. voicemail is on by default, so the first PUT takes the calls unless it sends "voicemail": false and no forward_to. Never silent: a number whose calls go to another webhook or TwiML app answers 409 voice_webhook_in_use with current: { voice_url, voice_application_sid } and changes nothing; send "replace": true to take it. The previous set-up is put back when inbound calling is switched off or the number is disconnected.
| Error | When |
|---|---|
400 invalid_request | A field is malformed, or forward_to is the number itself |
403 forbidden | A chatbot_id this key may not use, or null with a key limited to chatbots |
404 number_not_connected | Connect the number first |
404 not_found | chatbot_id isn't one of the workspace's chatbots |
404 number_not_found | The number is no longer on the Twilio account |
409 voice_webhook_in_use | See above |
409 voice_on_sip_trunk | The number's calls go to a SIP trunk: remove it from the trunk in Twilio first |
409 ai_unavailable, chatbot_required | AI answering isn't on yet, or the number has no chatbot |
409 not_connected, needs_reconnect | Credentials missing or refused |
422 voice_not_supported | The number can't take calls |
502 ai_setup_failed | The AI could not be set up: the other settings were saved, AI answering stays as it was. Try again. |
502 twilio_unavailable | Twilio could not be reached, or didn't update the number |
GET /numbers (voice:read) lists the connected numbers' settings; GET /numbers/{sid} reads one. Besides the fields above, each has sid, phone_number, capabilities, inbound_calls (ChatSa takes the number's calls now) and ai_ready (AI answering is on and set up).
AI answering#
PUT /numbers/{sid} with { "ai_answers": true, "greeting": "Thanks for calling Acme Plumbing!", "chatbot_id": "6f1c…" }. The number must be tied to a chatbot (409 chatbot_required otherwise); a chatbot_id in the same request does it.
- The AI answers from the chatbot's knowledge, in its voice and language (or the caller's, when they speak another), and can ask your connected app who is calling and pass on questions only your data can answer (see Connect).
- On a North American (+1) number it says first that it is the business's AI assistant (California SB 1001): "Hi, you've reached Acme Plumbing's AI assistant. This call is recorded. Thanks for calling Acme Plumbing!" On other numbers it opens with the greeting, then "This call is recorded." It never claims to be a person or denies being an AI.
- AI calls are always recorded.
- With
forward_toset, it can transfer the caller to a person; if nobody answers, the missed-call text and voicemail follow. Withoutforward_to, it offers to take a message. - AI calls use the workspace plan's voice minutes. If the AI can't take a call (less than a minute left on the plan, for example), the call goes on as if AI answering were off:
forward_to, then voicemail. - AI calls last at most 15 minutes.
The Call object and call.completed#
{
"id": "5d3f…",
"direction": "outbound",
"ai": false,
"mode": "bridge",
"from": "+14155550123",
"to": "+14155550199",
"contact": "+14155550199",
"agent_phone": "+14155550111",
"status": "completed",
"outcome": "conversation",
"agent_answered": true,
"client_answered": true,
"answered_by": "unknown",
"both_spoke": true,
"both_spoke_basis": "answered_duration",
"duration_sec": 120,
"talk_sec": 95,
"recording_url": "https://www.chatsa.co/api/v1/voice/recordings/5d3f…?kind=call&expires=…&signature=…",
"recording_expires_at": "…",
"voicemail_url": null,
"voicemail_duration_sec": null,
"transferred": false,
"transcript": null,
"summary": null,
"missed_call_text_id": null,
"chatbot_id": null,
"twilio_call_sid": "CA…",
"started_at": "…",
"ended_at": "…"
}
mode:bridge(a rep's call),forward(an inbound call rung through),voicemail, orai. An AI call keepsaiafter a transfer (transferred: true).contactis the customer;agent_phoneis the rep, or theforward_tonumber rung for an inbound call.statusis Twilio's call status (queued,ringing,in-progress,completed,busy,no-answer,failed,canceled), orpendingafter a timeout.outcome:conversation,short,agent_no_answer,no_answer,busy,failed,canceled,missedorvoicemail;in_progressuntil the call ends.answered_by: with voicemail detection,human,machine,faxorunknown; without it,unknownonce the customer answered, elsenull.both_spokeis what to count as a real conversation: for people's and forwarded calls, both sides answered (not a machine or fax, when detection is on) and talked at least 10 seconds; for AI calls, the caller spoke in the transcript.- AI calls carry
transcript(Agent:/User:lines) andsummary. Theirrecording_urlis the AI conversation's recording, or the person's part after a transfer withrecord_inboundon. missed_call_text_idis the id of the text sent after a missed call; read it withGET /sms/messages/{id}.
call.completed (data = the Call object) is sent once per call, when the call has ended and its recording, voicemail or AI transcript has arrived. If one never arrives, it is sent without it 10 to 15 minutes after the call ended. call.voicemail (id, from, to, duration_sec, recording_url, recording_expires_at, at) is sent when a voicemail is ready. Subscribe to call.* or each event (Webhooks); they reach your endpoints the same way as SMS events.
Recordings#
recording_url and voicemail_url are signed links, valid 1 hour, that need no API key: the link is the authorization. An expired or altered link answers 404; GET /calls/{id} gives fresh ones. Links in events expire an hour after the event was made, retries included, so fetch the audio promptly or read the call again. Follow redirects: a Twilio recording (MP3) may come as a redirect to Twilio's own short-lived link.
ChatSa stores no audio: recordings stay in the business's Twilio account (people's and forwarded calls, voicemail) or with ChatSa's voice provider (AI calls), and a person's erasure deletes them there too.