Add Telephony to a Gemini Live Agent

Google for DevelopersAbout 3 min readApr 22, 2026Watch original
THE SUMMARYAI-generated

Key Concepts

  • Gemini 1.5 Flash Live API: A real-time, multimodal AI model capable of low-latency voice and vision interaction.
  • WebSockets: The communication protocol used to maintain a persistent, bidirectional connection between the AI and the telephony provider.
  • Twilio Media Streams: A Twilio feature that allows streaming audio data to and from a WebSocket server.
  • FastAPI: A modern Python web framework used to build the server that proxies communication between Gemini and Twilio.
  • PCM vs. Mu-law: Audio encoding formats; Gemini outputs 24kHz 16-bit PCM, while Twilio telephony typically requires 8kHz mu-law, necessitating real-time conversion.
  • Google Cloud Run: A managed compute platform for deploying containerized applications.

1. Integration Architecture

The system functions by bridging the Gemini Live API with the public telephone network via Twilio. The architecture relies on a FastAPI server acting as a middleware proxy.

  • Inbound Calls: When a call hits a Twilio number, Twilio initiates a WebSocket connection to the FastAPI server. The server then establishes a session with the Gemini Live API.
  • Outbound Calls: The server uses the Twilio SDK to initiate a call via a POST request, subsequently linking the call to the Gemini WebSocket stream.
  • Data Handling: The TwilioHandler manages the audio buffer. Because of the discrepancy in audio standards (24kHz PCM vs. 8kHz mu-law), the handler must perform on-the-fly transcoding to ensure audio compatibility.

2. Development Methodology

The presenter emphasizes a "coding agent-first" approach to development:

  • Coding Agents: Tools like Antigravity, Cursor, or Claude Code are used to generate the boilerplate code and integration logic.
  • SDK Utilization: Developers are encouraged to use the Google Gen AI Python SDK, which includes built-in support for Gemini Live.
  • GitHub Resources: End-to-end example applications are available on GitHub, specifically those containing the TwilioHandler implementation.
  • Coding Skills: Users can install "Gemini Live API coding skills" into their IDEs to receive context-aware assistance while building.

3. Deployment Framework (Google Cloud Run)

To deploy the application, the following steps are required:

  1. Environment Setup: Enable Google Cloud Run, Cloud Build, and Secret Manager (to securely store API keys for Gemini and Twilio).
  2. Configuration: Store the Twilio Account SID, Auth Token, and Gemini API keys within the Secret Manager.
  3. Deployment: Once the container is built and deployed to Cloud Run, the platform provides a deployment URL. This URL is then configured within the Twilio Console to point to the inbound/outbound endpoints.

4. Partner Ecosystem

For developers who prefer not to manage the complexities of WebRTC, WebSocket connectivity, or audio transcoding, the presenter recommends utilizing specialized partner integrations:

  • Platforms: Life Kit, Pipe Cat, Fish Jam, Vision Agents, Voximplant, and Agora.
  • Value Proposition: These partners provide pre-built telephony infrastructure, allowing developers to focus on the AI persona rather than the underlying network plumbing.

5. Key Takeaways

  • Multimodality: The same Gemini Live agent can be deployed across different interfaces (phone via Twilio and web via browser) using a shared handler logic.
  • Real-time Capability: By leveraging WebSockets, the system achieves the low latency required for natural, human-like voice conversations.
  • Extensibility: The system is designed to be "thin," meaning the core logic resides in the Gemini Live API, while the Twilio integration acts as a lightweight bridge.

Notable Quote: "If you don't want to worry about [audio conversion] yourself, do use one of these partner integrations, and you'll get up and running in no time." — Thor, regarding the complexity of telephony infrastructure.

Conclusion

The integration of Gemini 1.5 Flash with Twilio via Google Cloud Run provides a robust framework for building real-time, voice-enabled AI agents. By utilizing existing GitHub templates and AI coding assistants, developers can bypass significant infrastructure hurdles. The primary technical challenge remains the conversion of audio formats, which can be solved either through custom TwilioHandler logic or by leveraging established third-party WebRTC partners.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.