Voice calls (phone, via LiveKit)
A voice agent can take part in a phone call that your telephony already handles. Your system answers or places the call, puts it in a LiveKit room, and asks us to join. The agent then joins that room as a participant: it hears the caller, answers them, and leaves when the call is over. We never touch your SIP trunk or numbers.
caller ⇄ your SIP trunk ⇄ your LiveKit server ⇄ (room) ⇄ Senaiy voice agent
▲
your call-centre app ── POST /v1/agents/{agent}/calls (call details + room credentials) ──▶ Senaiy
Everything here uses an API key with the agents.run scope (Authentication).
Responses are wrapped in {"message": …}; errors follow Errors and limits.
All times are UTC, ISO 8601 with milliseconds and Z.
1. Start: send the agent into the room
The agent ids come from GET /v1/agents?agent_type=Voice, which lists the voice agents in the key's
project: name is the id, alongside agent_name and status.
What a call of an agent takes: GET /v1/agents/{agent_id}
Build your "start AI call" form from this, and validate before you call:
{"message": {
"id": "acme-sana-voice-agent", "agent_name": "Sana Voice Agent", "agent_type": "Voice", "status": "Active",
"calls": {
"call_types": ["Inbound", "Outbound"],
"overridable_settings": ["objective", "script"],
"max_call_minutes": 30,
"context_schema": {
"schema": "lnj1uarh07", "schema_name": "Outbound sales call (ServeFast)", "schema_version": 4,
"json_schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object",
"title": "Outbound sales call (ServeFast)", "x-schema-version": 4,
"required": [], "additionalProperties": false,
"properties": {
"contact_name": {"type": "string", "title": "Customer name", "x-title-ar": "اسم العميل",
"description": "As addressed on the call, e.g. Ms Areej",
"x-description-ar": "كما يُنادى في المكالمة، مثل: أستاذة أريج"},
"customer_email": {"type": "string", "format": "email"},
"mobile": {"type": "string", "format": "phone", "pattern": "^\\+?[0-9][0-9 ()\\-]{5,19}$"},
"contact_gender": {"type": "string", "enum": ["أنثى", "ذكر"]},
"product": {"type": "string", "default": "ServeFast"}
}
}
},
"post_call_schema": {"schema": "lnk56a5pg7", "schema_version": 2, "json_schema": {"...": "..."}}
}
}}
json_schemais JSON Schema 2020-12, the same schema the platform validatescontextagainst. Unknown keys are refused (additionalProperties: false).- Labels:
title/descriptionin English,x-title-ar/x-description-arin Arabic, where the agent's builder wrote them.x-sensitivityispublic,personalorconfidential.x-given-only: truemarks a field only you set (for example your notes to the agent): the agent never records into it during the call. - Formats:
date(YYYY-MM-DD),date-time,email, andphone(digits with an optional leading+, also given aspattern).enumlists the allowed values;defaultis filled in when you leave the field out. schema_versionchanges when the agent's builder changes the fields. A call uses the version that is current when it is created.post_call_schemais the shape of the call'soutcome(section 4), so you can map it to your CRM.
POST https://platform.senaiy.ai/v1/agents/{agent_id}/calls
Authorization: Bearer sk-sf-...
Content-Type: application/json
{
"call_type": "Inbound",
"external_call_id": "CALL-00174",
"contact_ref": "customer-8812",
"context": {
"contact_name": "Sara",
"call_id": "CALL-00174"
},
"overrides": {
"objective": "Confirm the interview date"
},
"livekit": {
"url": "wss://livekit.your-company.com",
"room": "call-7781",
"token": "<access token for the agent>",
"caller_identity": "sip_+966500000000",
"answer_mark": true
},
"greeting": {"prebuffer": true, "interruptible": false}
}
| Field | Required | Meaning |
|---|---|---|
livekit.url |
yes | Your LiveKit server, wss://…. It must be reachable from the internet. If it is on a private network next to our platform, ask us to allow it. |
livekit.room |
yes | The room your telephony created for this call. The caller must be in this same room. |
livekit.token |
yes | A LiveKit access token for the agent: it must allow joining room, publishing audio, subscribing, and publishing data. Give it its own identity (for example senaiy-agent) and keep it valid for at least 10 minutes. We pass it to the voice runtime to join, and we never store it. |
livekit.caller_identity |
recommended | The caller's participant identity (your SIP participant). The call ends when this participant leaves. Without it, the call ends when the last other participant leaves. |
livekit.answer_mark |
recommended for outbound | true when your telephony marks the moment the customer really answers (see When the agent greets). The agent then waits for that mark before it speaks. |
greeting.prebuffer |
no | true: the agent prepares its opening, text and audio, as soon as it is in the room, and plays it the moment the customer answers (see When the agent greets). Default false: the opening is made after the answer. |
greeting.interruptible |
no | false: nothing the customer says stops the opening (a first "alo" no longer cuts it off). What they say while it plays is not heard. Default true. |
call_type |
no | Inbound (default) or Outbound. It changes how the agent opens and speaks. |
external_call_id |
no | Your own id for the call. The agent sees it on every call, so its tools can find the call; it also comes back on every read and webhook. |
contact_ref |
no | Who the call is with: your customer id, a phone number, and so on. A later call with the same contact_ref can continue from this one (opening mode Continue). |
context |
no | Values for the agent's context schema (read it with GET /v1/agents/{agent_id}). They are validated before the call exists: unknown keys, wrong types or a missing required field are refused, with every problem listed. |
overrides |
no | Call settings the agent allows a call to change. The agent's builder ticks these under What a call may change: objective, script, instructions, opening_mode, opening_instructions, opening_template, language, dialect, tts_voice, max_call_minutes, post_call_instructions, and tools, which can only narrow the agent's tools. A setting the agent does not allow is refused, not ignored. |
Response:
{"message": {"call_id": "kbr4fvbthq", "status": "Created", "call_type": "Inbound",
"channel": "Phone", "thread": "kbrr5b16ep", "joining": true}}
The agent joins within a second. It speaks first according to its opening mode (a greeting
generated from the context, a template, or silence until the caller speaks). If the agent cannot be
sent into the room, the call is recorded as Failed and you get an error. If no caller is in the room
60 seconds after the agent joins, it leaves and the call is Failed with reason nobody joined the
room. A phone that is still ringing counts as a caller in the room.
Call us before you dial: send this request as soon as the room exists, and originate the call once it returns. The agent is in the room before the customer can say "hello".
When the agent greets
The agent greets only once the customer has answered, never while the phone rings. For a SIP
participant (LiveKit participant kind SIP) the answer is, in order:
- Your answer mark, when the call has
livekit.answer_mark: trueor the SIP participant carries thesf.answeredattribute: the agent greets whensf.answeredbecomes"1", or when it receives the data message{"type": "call.answered"}in the room. Setsf.answeredto"0"when you create the SIP participant and to"1"on the real answer. - Otherwise, LiveKit SIP's own status:
sip.callStatus=active. Some carrier routes reportactivebefore the customer picks up, so use the mark on those routes.
With greeting.prebuffer: true, the agent makes its opening while the phone rings. The model
writes it from the call's context, and the audio is synthesised and held. It plays the instant the
answer above arrives: the first audio leaves within a few milliseconds of the mark, instead of after
the 5–6 s it takes to make the opening.
- While the phone rings, nothing on the line is taken as the customer: no ringback, early media
or carrier message.
- Costs and records. If nobody answers, the opening was made and billed but never played. The
call ends Failed as before, and its transcript holds the unplayed opening.
- Message time. The opening's message is written before the answer, so measure greeting latency
from the audio, not from the message's time.
- Use it with the answer mark, or on routes whose sip.callStatus reports the real answer.
Otherwise the opening plays on a false active as before.
When the call names caller_identity, the agent waits for that participant only: a listener or recorder you add to the room is never greeted. Without it, a participant of kind STANDARD (a web or app caller) is answered as soon as it joins. Participants
of kind AGENT (your own services in the room) are not callers: the agent does not greet them, and
the call does not end when they leave. It ends when caller_identity leaves or, without it, when the
last caller leaves.
What the agent hears
The agent hears every other participant in the room, mixed into one stream, as a phone line would. If a supervisor listens in, give them a muted microphone.
2. During the call: messages the agent sends to the room
The agent publishes reliable LiveKit data messages (JSON, UTF-8) to everyone in the room. Listen
with room.on("data_received") in your LiveKit SDK and act on type: "senaiy.call_control":
{"type": "senaiy.call_control", "call": "kbr4fvbthq", "action": "transfer",
"destination": "Billing queue", "reason": "Sara asks to change her payment plan; identity verified."}
action |
When | What your system should do |
|---|---|---|
hold |
The agent put the caller on hold while it works. max_seconds says how long at most. The caller's speech is ignored meanwhile. |
Optional: play hold music to the caller. |
resume |
The hold is over. | Stop the hold music. |
transfer |
The agent handed the call over. It has already told the caller, and this message arrives after its last words. Then it leaves the room. | Transfer the caller's leg to destination. reason is the summary for whoever picks up. |
end |
The agent ended the call: the conversation was over, the caller stopped answering, or the call reached its maximum length (reason). After the agent's goodbye it waits for the caller's, or 4 s of silence, before sending this. It leaves right after. |
Hang up the caller's leg, or route it elsewhere. |
Transfer destinations are set per agent in the portal: Voice settings → Call → Hand-over destinations, one per line. For phone calls, put the name your call centre routes on, with nothing after the bar:
Billing queue |
Supervisor desk |
Admissions office | admissions@your-company.com
A name followed by users also sends those users a task and a notification with the summary. The agent can only transfer to a name on this list.
The room also receives Pipecat's live transcript messages ("label": "rtvi-ai", types such as
user-transcription and bot-transcription). You can show them live, but they are informational
and may change. Use GET /v1/calls/{id} or the webhook for the record.
The agent leaving the room (participant_disconnected for its identity) always means it is done.
No listener in the room? Subscribe to the call.ended webhook instead (section 4). It arrives
a second or two after the agent has left, with status (Completed, Transferred or Failed),
end_reason, transfer_destination and transfer_summary, so your server can transfer or hang up
the caller's leg without being in the room. Hold and resume aren't sent this way: the agent mutes the
caller itself, and hold music is optional.
3. Ending the call from your side
- The caller hangs up: their participant leaves, the agent leaves, and the call is recorded. You don't need to do anything.
- A person takes over, or you need the agent out:
POST https://platform.senaiy.ai/v1/calls/{call_id}/end
{"reason": "a person picked up"}
→ {"message": {"call_id": "kbr4fvbthq", "left": true}}
The agent leaves the room at once, without a goodbye. Your caller stays connected. left: false
means the agent was no longer in the call.
A call lasts at most its max_call_minutes (the agent's setting, or the call's override). At that
point the agent wraps up and sends end.
A person takes over: sleep and wake
To have a person take the call while the agent stays in the room and can come back:
POST https://platform.senaiy.ai/v1/calls/{call_id}/sleep
→ {"message": {"call_id": "kbr4fvbthq", "asleep": true}}
POST https://platform.senaiy.ai/v1/calls/{call_id}/wake
{"instruction": "Confirm the new delivery date with the customer"}
→ {"message": {"call_id": "kbr4fvbthq", "asleep": false}}
You can also send them as reliable data messages in the room, the way you send call.answered:
{"type": "senaiy.sleep"} and {"type": "senaiy.wake", "instruction": "…"}.
Asleep, the agent:
- stops speaking at once, including any answer still being written;
- says nothing and takes no turns, whoever speaks;
- makes no silence reminders and no time-limit wrap-up, and never ends, holds or transfers the call;
- holds any background tool results until it wakes;
- keeps the transcript. What is said goes into the call's messages as user lines starting with
(heard while asleep). The agent hears the room as one stream, so the customer and your person
are not told apart;
- shows the call status as Asleep.
Woken, the agent takes the call back from everything said while it slept and your
instruction, if any. Without one, it says in a short line that it is back and carries on from
where the conversation is.
Usage. Time asleep is not billed and does not count towards max_call_minutes.
Errors. Waking an agent that is awake, or putting to sleep one that is asleep, changes nothing. Only a phone call in a LiveKit room can sleep. A call that has ended, or that the agent has left, returns an error.
4. After the call: the record and the webhook
GET https://platform.senaiy.ai/v1/calls/{call_id}
{"message": {
"id": "kbr4fvbthq", "agent": "acme-sana-voice-agent", "call_type": "Inbound", "channel": "Phone",
"status": "Completed", "contact_ref": "customer-8812", "external_call_id": "CALL-00174",
"joined_at": "2026-11-17T18:00:31.204Z", "started_at": "2026-11-17T18:00:33.950Z", "ended_at": "2026-11-17T18:03:35.402Z",
"duration_seconds": 184.2, "end_reason": "handed over to Billing queue",
"config": {"objective": "...", "language": "ar-SA", "...": "..."},
"context": {"contact_name": "Sara", "call_id": "CALL-00174"},
"learned": {"preferred_date": {"value": "2026-12-01", "at": "2026-11-17T18:01:40.118Z", "run": "..."}},
"outcome_status": "Completed",
"summary": "Sara confirmed the interview on 1 December and will bring her passport.",
"outcome": {"summary": "...", "outcome": "Confirmed", "follow_up_on": "2026-11-30"},
"outcome_problems": null,
"tasks": [{"tool": "lookup_application", "mode": "Background", "status": "Completed", "...": "..."}],
"messages": [
{"role": "assistant", "content": "السلام عليكم، أستاذة أريج؟ …", "at": "2026-11-17T18:00:35.012Z", "offset_ms": 3808},
{"role": "user", "content": "إيه نعم، تفضلي", "at": "2026-11-17T18:00:39.512Z", "offset_ms": 8308},
{"role": "tool", "tool": "update_call_context", "status": "ok", "arguments": {"key": "meeting_slot", "value": "الثلاثاء 10 صباحاً"},
"result": "{\"ok\": true, \"recorded\": \"meeting_slot\"}", "duration_ms": 41, "at": "2026-11-17T18:02:10.330Z", "offset_ms": 99126},
{"role": "tool", "tool": "lookup_application", "mode": "background", "task": "v89ksksbnn", "status": "Completed",
"arguments": {"application_id": "APP-1042"}, "result": "…", "duration_ms": 6457, "at": "2026-11-17T18:02:30.902Z", "offset_ms": 119698}
]
}}
Times are UTC, ISO 8601 with milliseconds and Z. joined_at is when the agent joined the call
(in your LiveKit room, or the browser connected); started_at is when the conversation started (the
first participant was there and the agent opened). Each message's offset_ms counts from
joined_at (from started_at for calls made before joined_at existed).
Messages are the call in order: user (the caller), assistant (the agent) and tool. A tool
message is a tool the agent used, with its arguments, result, status (ok / failed) and
duration_ms. A background tool appears twice: when it was started (its result says it is running)
and, with "mode": "background", when its result came. Tool arguments and result are kept only
when payload logging is on for your organization and project (the platform team sets it); without it they are null.
status:Created→In Progress(On Hold,Asleep) →Completed|Transferred|Failed.learned: what the agent recorded during the call, against the context schema's own fields.outcome: the agent's post-call output. It always has asummary, plus the fields of the output schema set under Voice settings → After the call. It is produced a few seconds after the call ends.outcome_statusisPendinguntil then, then:Completed: the output matched the schema.Needs Review: it didn't, andoutcome_problemssays why.Failed: nothing usable came back.
call.ended comes as soon as the agent is out of the call:
{"event": "call.ended", "data": {"id", "agent", "external_call_id", "channel", "room", "caller_identity",
"contact_ref", "status", "end_reason", "transfer_destination", "transfer_summary", "joined_at", "started_at",
"ended_at", "duration_seconds"}}, times in UTC as above.
Webhook. Subscribe an endpoint to call.completed (portal: Developer → Webhooks). It is sent
once the post-call output is ready, whether or not it succeeded. The body is
{"event": "call.completed", "data": <the same record as GET /v1/calls/{id}>}, signed as described
in Webhooks. Use data.external_call_id to match it to your call. This is how you update your CRM: you get the outcome
fields you defined, typed and validated.
5. Setting up an agent for phone calls (portal)
- Agents → New agent, type Voice. Choose the speech-to-text, the model and the voice. For Arabic, use a multilingual voice such as Flash v2.5; the picker marks English-only voices.
- Agents → Context schemas: define what a call carries (customer, application, order…), with English and Arabic labels. Pick it in the agent's Voice settings → Call.
- Voice settings → Call:
- the objective, opening mode and script
- which settings a call may change
- the hand-over destinations
- the maximum duration.
- Voice settings → After the call: the output schema (for example an outcome, a follow-up date or commitments) and instructions for filling it.
Tools tab: grant tools. On a voice agent each tool has a mode:
- Runs at once
- In background: the agent keeps talking and reports the result when it arrives
- Caller confirms: nothing runs until the caller agrees to what the agent read back.
Grant
end_call,transfer_call,hold_callandupdate_call_contextso the agent can control the call and record what it learns.- Try it in Playground → Voice Agent Playground in the browser. The same agent then takes phone calls through this API without any change.
Quick test with curl
curl https://platform.senaiy.ai/v1/agents/$AGENT -H "Authorization: Bearer $SENAIY_KEY"
curl -X POST https://platform.senaiy.ai/v1/agents/$AGENT/calls \
-H "Authorization: Bearer $SENAIY_KEY" -H "Content-Type: application/json" \
-d '{"external_call_id": "test-1",
"livekit": {"url": "wss://livekit.your-company.com", "room": "test-room",
"token": "'"$AGENT_TOKEN"'", "caller_identity": "tester"}}'
# join the same room as "tester" from any LiveKit client and speak
curl -X POST https://platform.senaiy.ai/v1/calls/$CALL/end -H "Authorization: Bearer $SENAIY_KEY"