Example: Function calling
This example answers an inbound Voximplant call, connects it to OpenAI Realtime, and handles function calls in VoxEngine.
It includes three tools:
get_weatherhang_upwarm_transfer
⬇️ Jump to the Full VoxEngine scenario.
Prerequisites
- Set up an inbound entrypoint for the caller:
- Phone number: https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers
- WhatsApp: https://voximplant.com/docs/guides/integrations/whatsapp
- SIP user / SIP registration: https://voximplant.com/docs/guides/calls/sip
- Voximplant user: https://voximplant.com/docs/getting-started/basic-concepts/users (see also https://voximplant.com/docs/guides/calls/scenarios#how-to-call-a-voximplant-user)
- Create a routing rule that points the destination (number / WhatsApp / SIP username) to this scenario: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Store your OpenAI API key in Voximplant
ApplicationStorageunderOPENAI_API_KEY.
Session setup
The scenario uses sessionUpdate to define:
- Realtime model instructions
server_vadturn detection- tool schemas (
tools) tool_choice: "auto"
Tool definitions are declared in SESSION_CONFIG.session.tools and sent right after SessionCreated.
Connect call audio
After SessionUpdated, the example bridges call audio to OpenAI:
Function calling flow
The example listens for OpenAI.RealtimeAPIEvents.ResponseFunctionCallArgumentsDone, parses arguments, and returns tool output with conversationItemCreate (type: "function_call_output"), then calls responseCreate so the assistant continues.
get_weather
Returns a stub weather payload for the requested location.
hang_up
Sets pendingHangup = true, returns hangup_scheduled, and hangs up after assistant audio completes (ResponseOutputAudioDone or WebSocketMediaEnded).
warm_transfer
Places a PSTN leg, plays a brief intro to the callee, then bridges the original caller to the transfer leg after a delay.
Barge-in
The scenario clears buffered model audio when caller speech starts:
Notes
- Tool implementations are demo stubs. Replace with real APIs and transfer logic for production.
- The warm transfer demo uses a default destination if the model does not provide one.
See the VoxEngine API Reference for more details.