Bot stream with Legs API
Start a bidirectional AgentStream session from Legs actions — with an optional greeting while the bot warms up.
For the full outbound/inbound ExoML path, see Programmable Voice with AgentStream.
Patterns
| Goal | Pattern |
|---|---|
| Bot-first / tech support | leg_answered → start_stream |
| Sales / collections (no dead air) | leg_answered → start_stream + start_say → on stream_started → stop_say |
| Per-call stream URL | Decide url in your service at runtime |
Authentication
HTTP Basic Auth. Content-Type: application/json
Base URL: https://cpaas-api.in.exotel.com/v2/accounts/{account_sid}
(Singapore: cpaas-api.exotel.com)
Start stream
Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
direction | Yes | String | bidirectional |
url | Yes | String | Bot WebSocket URL |
content_type | No | String | e.g. audio/x-mulaw;rate=8000 |
Example request
curl -u '<api_key>:<api_token>' -X POST \
'https://cpaas-api.in.exotel.com/v2/accounts/<account_sid>/legs/<leg_sid>/actions/start_stream' \
-H 'Content-Type: application/json' \
-d '{
"direction": "bidirectional",
"url": "wss://bot.example.com/stream",
"content_type": "audio/x-mulaw;rate=8000"
}'
Try It
Parallel greeting
Start say
curl -u '<api_key>:<api_token>' -X POST \
'https://cpaas-api.in.exotel.com/v2/accounts/<account_sid>/legs/<leg_sid>/actions/start_say' \
-H 'Content-Type: application/json' \
-d '{ "text": "Connecting you now.", "loop": 0 }'
Try It
Stop say
curl -u '<api_key>:<api_token>' -X POST \
'https://cpaas-api.in.exotel.com/v2/accounts/<account_sid>/legs/<leg_sid>/actions/stop_say'
Try It
After stream starts
Your bot receives the same WebSocket protocol events as Voicebot applet sessions.