/conversation/connectOpen a session for an agent. Server-side; uses your API key directly.
Connect
Starts a WebRTC session for the given agent. You get back a session_id and an ice_config. Pass the ice_config.iceServers directly into new RTCPeerConnection({ iceServers }) on the browser side.The session_id is the same UUID as the underlying conversation and call records, so you can use it later for GET /conversations/{id}/transcript and GET /recordings/{id}/audio once the call ends.Each call creates persistent records; do not invoke in a tight retry loop. Public agents: if the agent has public_access on, a browser or app can call this endpoint with only the agent_id and no API key. Restrict which sites may embed it with the agent's allowed_origins.WebSocket sessions: with transport: "websocket", the response is a session_id and a ws_url instead, for your client to stream the conversation over (see WS /ws/v1/conversation/:session_id below). Only an API key can open one. By default the agent greets the user first; set direction to outbound when your side placed the call.
Request body
9agent_idstring (UUID)requiredThe agent UUID to start the session with. Must belong to the calling account.
dynamic_variablesobjectoptionalValues for the agent's
{{variable}}placeholders, for this session only — nothing is saved back to the agent. Same shape asPOST /calls/trigger: a flat object of strings, numbers or booleans. Values you send override the agent's stored defaults; a placeholder with neither is never read out as braces: the model sees[name: not provided]in its place, and the spoken opener drops it. Keys may not start withsystem__— those are filled in for you, andsystem__caller_id/system__called_numberare empty on a browser call because there is no phone leg. On a WebSocket session,caller_phonefills the one for its side of the call. UnlikePOST /calls/trigger, an unsupportedsystem__placeholder is treated the same way rather than rejected. Ignored when the session itself is keyless — a public agent reached without an API key, or a call token — because those credentials live in the browser; those sessions use the agent's own defaults. Reaching that same public agent with your API key personalizes normally: what decides is the credential, not the agent.transportstringoptionalwebrtc(the default) for a browser or app peer, orwebsocketto stream the conversation's audio over a WebSocket from your own code. Awebsocketsession needs an API key and returns aws_urlinstead of anice_config.directionstringoptionalWebSocket sessions only.
inbound(the default): the agent greets the user as soon as the socket connects.outbound: your side placed the call, so the agent lets the person who answered speak first, and greets them after their hello or after 3 seconds of silence. Ignored on a WebRTC session.protocolstringoptionalWebSocket sessions only.
aethex(the default): Aethex's JSON events, with what the user and the agent said as text.twilio: the Twilio Media Streams format, for systems that already speak it. Ignored on a WebRTC session.audio_formatstringoptionalWebSocket sessions only. The audio on the wire, both ways:
pcm_16000(16-bit PCM at 16 kHz, the default) orulaw_8000(G.711 µ-law at 8 kHz). Thetwilioprotocol takesulaw_8000only. Ignored on a WebRTC session.caller_phonestring (E.164)optionalWebSocket sessions only. The phone number of the person on the call, in E.164 format (for example
+14155550199), when the call has one. Saved as the call'sfrom_numberon an inbound session and itsto_numberon an outbound one, and fillssystem__caller_idorsystem__called_numberto match. Ignored on a WebRTC session.opener_playedbooleanoptionalWebRTC sessions only. Set it to
truewhen your app plays the agent'sfirst_messageto the user itself, before or while the call connects, for example from audio it keeps ready, so there is no silence while the call connects. The audio must say thefirst_messageas it reads once its placeholders are filled for this session. Mute the microphone while it plays (send no audio from the user): otherwise the agent may hear its echo as the user speaking. The user's audio reaches the agent only once the call is connected: if your audio can end before that, keep the microphone muted and show a connecting state until the connection is up. The agent then does not say it again: that text is added to the conversation as something the agent has already said, and the agent waits for the user to speak. If the user stays silent, the agent's usual check-ins still apply: they count from when the call connects, or from the end of your audio when you sendopener_duration_secs. With this flag your app, not the agent, delivers thefirst_message, so keep that in mind if it carries a required notice (a recording or AI disclosure, for example). The call recording does not contain your audio: a notice you play (a recording notice, for example) is not in the recording. Defaults tofalse. Ignored on a WebSocket session. The response'sopener_playedsays whether the agent takes your audio as played: start or keep playing it only when that istrue. Onfalsethe agent greets the user itself, because itsfirst_messageis empty once its placeholders are filled, or because the server does not know this flag; older servers leaveopener_playedout of the response, so treat a missing field asfalse.opener_duration_secsnumberoptionalWebRTC sessions with
opener_playedonly. How long your app's audio of thefirst_messageruns, in seconds, counted from when this request arrives, so start playing it as you send the request. The agent's first check-in on a silent user then waits until that audio has ended instead of counting from when the call connects, so it never talks over the end of a longfirst_message. From0to60. Without it, check-ins count from when the call connects.
Errors
10Missing or invalid API key.
Send a valid X-API-Key header or bearer token.
The agent speaks a local African language or Arabic, or a local dialect (dialect_style mixed or local): those are part of the Aethex enterprise platform. The agent reads language_available: false.
Use english or french in its standard form, or move the work to the Aethex enterprise platform.
The agent's voice is on a voice pool your account may not use, or the agent has no voice and no voice your account may use speaks its language. The body's kind and value name it.
Give the agent a voice from GET /voices, which lists only the ones your account may use.
API key lacks the calls:write scope.
Use a key with the required scope.
transport is websocket, but the request did not use an API key: for example a call token, or a public agent reached without one.
Open WebSocket sessions from your server with an API key.
Account is hard-blocked: subscription canceled past the grace window, or balance is zero with no payment method on file.
Re-subscribe, add a payment method, or top up credits, then retry.
The agent_id does not exist or does not belong to this account.
Verify via GET /api/v1/agents.
agent_id missing or not a valid UUID, or invalid dynamic_variables — not a flat object of strings, numbers and booleans, or a key using the reserved system__ prefix. Also a direction, protocol or audio_format outside its values, audio_format pcm_16000 with protocol twilio, or, on a WebSocket session, a caller_phone that is not in E.164 format.
Send a JSON body with a valid agent_id. If you send dynamic_variables, keep it a flat object of scalar values and drop any system__ key. Send caller_phone in E.164 format, such as +14155550199.
The account or shared backend has no free slot. Response body includes retry_after; response carries a Retry-After header.
Honor the Retry-After header and retry.
No backend slot can be reserved at all.
Retry shortly. If persistent, contact our team at [email protected].
