Example: Placing an outbound call
This example starts a VoxEngine session, places an outbound PSTN call, and bridges audio to Ultravox after the callee answers.
⬇️ Jump to the Full VoxEngine scenario.
Prerequisites
- Create a routing rule with this scenario attached (outgoing calls don’t use patterns) so you can run it from the Control Panel or trigger it via API: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Have a PSTN
destinationnumber you can dial (E.164 format), for example your mobile number. - Configure a valid outbound
callerId(for example, a rented Voximplant number or a verified caller ID): https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers - Pass
destinationandcallerIdas routing rule custom data (this example reads them fromVoxEngine.customData()):{"destination":"+15551234567","callerId":"+15557654321"}. - Store your Ultravox API key in Voximplant
ApplicationStorageunderULTRAVOX_API_KEY. - Configure tools (function calling): https://docs.ultravox.ai/tools/overview
About outbound Caller ID
VoxEngine.callPSTN(...) requires a valid callback-capable caller ID (for example, a rented Voximplant number or a verified caller ID). See https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers.
Launch the routing rule
For quick testing, you can start this outbound scenario 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 (max 200 bytes) with
destinationandcallerId:
For production, start the routing rule via Management API startScenarios (pass rule_id, and pass the same JSON string in script_custom_data): https://voximplant.com/docs/references/httpapi/scenarios#startscenarios
Place the outbound call
Outbound calls are placed with VoxEngine.callPSTN(number, callerid, parameters?).
In the full example, see VoxEngine.customData(), the destination / callerId parse, and the AppEvents.Started handler:
Alternate outbound destinations
The example includes commented‑out alternatives to place calls to other endpoints. Use these when you want to avoid PSTN or route internally:
- Voximplant users (
VoxEngine.callUser): calls another app user inside the same Voximplant application. Best for internal testing or app‑to‑app flows. - SIP (
VoxEngine.callSIP): dial a SIP URI to reach a PBX, carrier, or SIP trunk. Best for enterprise SIP endpoints. - WhatsApp (
VoxEngine.callWhatsappUser): place a WhatsApp Business‑initiated call (requires a WhatsApp Business account and enabled numbers).
Relevant guides:
- Users: https://voximplant.com/docs/getting-started/basic-concepts/users
- SIP: https://voximplant.com/docs/guides/calls/sip
- WhatsApp calls: https://voximplant.com/docs/guides/integrations/whatsapp-calls
Session setup
Ultravox uses a WebSocket API client created via Ultravox.createWebSocketAPIClient(...). The key inputs are:
endpoint: useUltravox.HTTPEndpoint.CREATE_CALL(orCREATE_AGENT_CALL).authorizations: includeX-API-Keywith your Ultravox API key.body: providesystemPrompt,model, andvoice.
Connect call audio
For outbound, create the Ultravox client and bridge audio after the callee answers (so the agent doesn’t speak into ringback):
Barge-in
Clear the output buffer when the caller starts talking to keep the conversation interruption‑friendly: