Example: Function calling
Example: Function calling
For the complete documentation index, see llms.txt.
This example answers an inbound call, enables Gemini tool calling, and sends tool responses back to the model.
⬇️ Jump to the Full VoxEngine scenario.
Gemini 3.1 Flash Live Preview
This page reflects the current gemini-3.1-flash-live-preview flow from Google’s Live API docs:
https://ai.google.dev/gemini-api/docs/models/gemini-3.1-flash-live-preview
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
- App 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 (phone number / WhatsApp / SIP username / app user alias) to this scenario: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Store your Gemini API key in Voximplant Secrets under
GEMINI_API_KEY.
Tool definitions
The full example also uses thinkingConfig: { thinkingLevel: "minimal" } to keep tool-calling turns responsive.
The example registers tools in connectConfig.tools using functionDeclarations and JSON Schema parameters:
Handling tool calls
Gemini sends tool calls via Gemini.LiveAPIEvents.ToolCall. Respond with sendToolResponse:
Notes
- The example uses the Gemini Developer API (
Gemini.Backend.GEMINI_API), not Vertex AI. - The current sample uses
gemini-3.1-flash-live-preview. - Tool implementations in the example are stubs. Replace with real integrations as needed.
Gemini 2.5 compatibility
If you are updating a 2.5 Gemini Live function-calling sample, switch the startup prompt from sendClientContent(...) to sendRealtimeInput(...) for 3.1. Also replace the older thinkingBudget field with thinkingLevel.
See the VoxEngine API Reference for more details.