Example: Function calling
This example answers an inbound call, connects it to Cartesia Line Agents, and uses an HTTP callback for tool actions (end_call, call_transfer).
Jump to the Full VoxEngine scenario.
Prerequisites
- Deploy a Cartesia Line Agent script that sends HTTP callbacks to VoxEngine for tool actions (see the Cartesia agent example).
- Store your Cartesia API key in Voximplant
ApplicationStorageunderCARTESIA_API_KEY - Store your Cartesia Agent ID in Voximplant
ApplicationStorageunderCARTESIA_AGENT_ID - Ensure your scenario can place outbound PSTN calls with a verified caller ID (used by transfer) - see How can I enable Caller ID for outbound calls
- Store a valid outbound caller ID in Voximplant
ApplicationStorageunderPSTN_CALLER_IDfor transfer PSTN dialing
Session setup
This setup is similar to the inbound example, with one extra control-plane step for tools:
AppEvents.Started: capture per-callaccessSecureURLassessionControlUrl.AppEvents.CallAlerting: answer the inbound call and (optionally) start recording.- Create
Cartesia.AgentsClientfromApplicationStorage. - Bridge media between caller leg and Cartesia.
- Start Cartesia session with any metadata to pass to the agent, including
vox_session_control_url.
Functional Call Execution
Architecture
Cartesia Line Agent currently provides limited controls over its WebSocket interface. Instead, we will use
VoxEngine’s AppEvents.HttpRequest as a callback endpoint for the Cartesia Agent to request telephony actions
(call transfer, hang up) in VoxEngine.
This allows the Line Agent to orchestrate complex call control flows while VoxEngine retains ownership
of telephony actions and routing decisions.

HTTP control model
This scenario uses the following control-plane pattern:
- VoxEngine gets a unique
accessSecureURLinAppEvents.Started. - VoxEngine passes that URL to Cartesia in
metadata.vox_session_control_url. - Cartesia Python tool handlers
POSTactions such as{"action":"end_call"}or{"action":"call_transfer"}. - VoxEngine receives those requests in
AppEvents.HttpRequestand executes telephony actions.
How AppEvents.HttpRequest is used
AppEvents.HttpRequest is the handoff point where Cartesia tool decisions become telephony actions:
- Cartesia sends an HTTPS
POSTto the per-callvox_session_control_url. - VoxEngine receives request content in
appEvent.content. - Scenario parses JSON and switches on
cmd.action. - Scenario executes telephony action (
hangup,callTransfer, bridge). - Scenario returns a JSON string response (
{"ok": true}) to acknowledge receipt.
Expected request payloads:
{"action":"end_call"}{"action":"call_transfer","summary":"optional short summary"}
Minimal response payload:
{"ok": true}
Passing the control URL and metadata to Cartesia
Here we pass information such as the control URL to Cartesia when we start the session.
Handling control actions in AppEvents.HttpRequest
High-level flows
Hang-up flow (end_call)
- Caller asks to end the call.
- Cartesia Python agent runs
end_call()and posts{"action":"end_call"}. - VoxEngine
AppEvents.HttpRequestreceives the action. - Scenario hangs up caller leg, closes Cartesia websocket, and terminates the session.
Transfer flow (call_transfer)
- Caller asks to transfer to a human.
- Cartesia Python agent sends transfer confirmation, then posts
{"action":"call_transfer","summary":"..."}. - VoxEngine
AppEvents.HttpRequestcallscallTransfer(...). - Scenario detaches caller from Cartesia (
stopMediaBetween+ websocket close), which makes this a blind transfer handoff pattern. - Scenario dials consult PSTN call with
VoxEngine.callPSTN(...)usingPSTN_CALLER_ID. - On consult answer, scenario bridges caller to consult leg with
VoxEngine.sendMediaBetween(callerLeg, consultLeg). - If consult call fails, scenario logs failure and hangs up caller leg.
Cartesia agent example (Python)
The full Cartesia Line Python agent example used with this callback pattern:
This Python sample expects metadata.vox_session_control_url and uses it to call back into VoxEngine.
Notes
Voximplant
- Voximplant Cartesia module API reference: https://voximplant.com/docs/references/voxengine/cartesia
- Working with API requests guide: https://voximplant.com/docs/guides/voxengine/api
- HTTP Callback guide: https://voximplant.com/docs/guides/management-api/callbacks
Cartesia
- Cartesia Line Agents documentation: https://docs.cartesia.ai/line-agents/overview
- Cartesia Line web calls event model: https://docs.cartesia.ai/line/integrations/web-calls