Example: Placing an outbound call
This example starts a VoxEngine session, places an outbound PSTN call, and bridges audio to Cartesia Line Agents once the callee answers.
Jump to the Full VoxEngine scenario.
Prerequisites
- Create a Cartesia Line Agent in the Cartesia Voice Agents portal
- Store your Cartesia API key in Voximplant
ApplicationStorageunderCARTESIA_API_KEY - Store your Cartesia Agent ID in Voximplant
ApplicationStorageunderCARTESIA_AGENT_ID - Ensure outbound calling is enabled for your Voximplant application and your caller ID is verified
Outbound call parameters
The example expects destination and caller ID in customData passed to the routing rule:
Launch the routing rule
For quick testing from the Voximplant Control Panel:
- Open your Voximplant application and go to the Routing tab.
- Select the routing rule that has this scenario attached.
- Click Run.
- Provide custom data JSON with
destinationandcallerId.
For production, start the routing rule via Management API startScenarios and pass the same JSON in script_custom_data:
https://voximplant.com/docs/references/httpapi/scenarios#startscenarios
Session setup
Outbound setup follows this order:
- Parse
destinationandcallerIdfromVoxEngine.customData(). - Place the PSTN call with
VoxEngine.callPSTN(...). - Wait for
CallEvents.Connected. - Create
Cartesia.AgentsClient. - Send
start(...)metadata withmode: "outbound". - Bridge call media to the Cartesia client.
The scenario deliberately creates and starts the Cartesia session only after the callee answers:
Use outbound mode metadata for this scenario:
Then connect audio between the PSTN leg and Cartesia:
The example also adds:
CallEvents.FailedandCallEvents.Disconnectedhandlers for cleanup.- A demo hangup timer to avoid indefinitely running sessions.
- Cartesia event logs (
ACK,ConnectorInformation,Clear, media started/ended) for debugging.
Notes
See the VoxEngine API Reference for more details.