Getting Started With Voice AI: Choosing Your Path on Twilio
Time to read:
Getting started building a Voice AI agent from scratch involves a lot of moving parts: telephony, real-time audio streaming, transcription, speech generation, and interruption handling - and that’s before you even work on your actual agent’s capabilities. If you wire all of that together by hand, it's easy to spend your first week debugging audio codecs and turn-taking logic instead of building the actual agent.
Because Twilio takes an open infrastructure approach, there are many possibilities of how to architect your Voice AI Agent. The hardest part of getting started might just be picking the right abstraction layer!.
Twilio gives you four entry points for building and testing voice AI agents. In this post, I’ll help you think through the trade-offs, choose the right path to start, and provide you all the resources you’ll need to keep going into production – no matter which path you choose.
Let’s walk some paths together.
Decision Factors
Before you spin up your repo, I’ll first help you narrow down your answers to some important architectural questions. Your answers will help point you to the right Twilio abstraction layer.
- Model Type: Cascaded vs Speech-to-Speech
- Control: Offload Voice Orchestration or build it yourself?
- Existing Stack: Are you hosting an agent or using a turn key vendor?
Now that you have an idea of the decisions you’ll need to make, let’s discuss what each one means.
Model Type: Cascaded vs Speech-to-Speech
Cascaded: Cascaded pipelines ( STT → LLM → TTS) let you customize voices and roles, using standard text-in, text-out LLMs paired with Speech-to-Text and Text-to-Speech engines. Everything passes through text, which makes it easy to inspect, log, and pair with deterministic tool calling or guardrails. Twilio’s Conversation Relay product architecture demonstrates a Cascaded Architecture:
Speech-to-Speech Models take audio in directly, and produce audio out directly – without a text step in between. This sometimes offers advantages to complexity and turn-recognition (the model might better interpret when you are done speaking), though can present downsides like locking you into a single, fixed voice identity and role. Also, no intermediate text step means you lose out on control, limited guardrails, logs and the ability to deterministically step in.
If you decide to build with a speech-to-speech model, you'll need either managed middleware that supports S2S or a direct audio/SIP connection to the model.
Control: Offload Voice Orchestration or build it yourself?
Even with a lightning fast LLM, making a phone call feel natural requires a lot of complexity. Rule following, natural conversation turn taking, and handling interruptions are just a few of the many concerns you’ll have to build around.
You can decide: do you want Twilio to manage that real-time voice orchestration, or do you want to own the raw audio stream and handle it yourself?
Existing Stack: Are you hosting an agent or using a turn key vendor?
Before you pick an integration, you have to decide whether to build or buy your AI Agent.
If you’re building on top of your own cloud or agent framework, Twilio can provide the right abstraction that simply handles voice orchestration and can bridge your LLM and the telephony networks. If you’re buying a managed Voice AI solution you don’t need Twilio to orchestrate the conversation at all, you simply need Twilio to connect your Agent to a phone number.
| Twilio Product | What Twilio Owns | What Your Code Owns | Best For |
|---|---|---|---|
| Twilio Agent Connect (TAC) | Connects your agent to Voice (and other channels like SMS) | Your agent, in the framework or cloud of your choice | The recommended starting point for most builders – especially if you want to decouple agent logic from voice architecture |
| Conversation Relay | Bridges to speech-to-text and text-to-speech providers, interruptions, turn-taking, and audio streaming | A WebSocket server that sends and receives text with your LLM | Hands-on control over a custom cascaded text LLM loop without touching raw audio |
| Media Streams | Raw bidirectional audio over WebSockets | Either the whole audio pipeline or a bridge to an S2S model | Direct audio bridges to Speech-to-Speech models or custom real-time audio processing |
| Elastic SIP Trunking | PSTN connectivity, phone numbers, and SIP routing | A connection to a SIP-capable AI platform | Turnkey Voice AI vendors or AI platforms that accept calls directly over SIP |
TAC vs. Conversation Relay vs. Direct S2S
Know which way you’re leaning? Once you have an answer for the factors listed, the choice usually comes down to three main build paths.
Twilio Agent Connect
Twilio Agent Connect (TAC) is an excellent way to get started building Voice AI Agents.
TAC is an SDK which you host that sits between your LLM application and Twilio’s products and services. It lets you keep your agent where it lives without writing custom telephony code, lets you add conversational monitoring and history, and even lets you later add additional conversation channels such as SMS or WhatsApp.
You can use it with an external agent framework, host it on your own cloud, or even wire up a Speech-to-Speech Model.
Conversation Relay
Conversation Relay is a great choice when you want direct, token-by-token control over a cascaded text LLM Loop. With Conversation Relay, Twilio handles the Voice Orchestration – STT, TTS and interruption handling – while you can simply build around text tokens.
This allows you to own the exact prompt pipeline, regardless of whether you’re using an external agent framework or have built your own.
Direct S2S (Media Streams/Elastic SIP Trunking)
If you’ve decided to use a managed Voice AI Vendor or Speech-to-Speech Infrastructure then you don’t need Twilio managing the conversation loop. Media Streams and Elastic SIP Trunking enable you to add Twilio’s telephony services to an existing AI Vendor’s managed Voice AI Stack.
Deep Dive: Choosing your Integration
Now that I’ve given you an overview of the paths, let’s dig a little deeper.
In this section, I’m going to zoom into the Twilio Agent Connect, Conversation Relay, Media Streams, and Elastic SIP Trunking paths and give you the resources you’ll need to prototype, test, and eventually go into production.
Between these resources and our Voice AI Agent Reference Architecture, we’ll have you talking to AIs in no time.
Twilio Agent Connect (TAC)
Twilio Agent Connect acts as the middleware that bridges Twilio's Voice and Messaging channels directly into your existing agent stack. These resources show how to use Twilio Agent Connect with your choice of provider and a selection of models, so you can see examples of what’s possible.
- Amazon Bedrock AgentCore - Build an omni-channel AI agent with Twilio Agent Connect and Amazon Bedrock AgentCore.
- Sample repo: twilio-agent-connect-aws-owlair
- Google Cloud - Twilio Agent Connect for Google Cloud.
- Sample repo: gemini-live-twilio-tac
- Microsoft Azure - Build a voice and SMS AI agent with Twilio Agent Connect and Microsoft Azure
- OpenAI speech-to-speech - Build a voice AI agent with GPT-Live and Twilio Agent Connect in Python or TypeScript.
- Video: How to build a voice AI agent (GPT-Live-1 + Twilio),
- Sample repo: pat-and-hueys-coffee
Want to go further? Twilio’s Conversation Memory lets you carry context across channels and sessions by adding Twilio’s Conversation Orchestrator and Conversation Memory to an AI Agent build with TAC, then add Conversation Intelligence to produce summaries and observations for future interactions. Our Conversational Agent Memory repo shows some of the how.
Conversation Relay
Conversation Relay takes the audio engineering off your plate so you can focus on the conversation loop. Twilio handles speech-to-text, text-to-speech, and interruption ("barge-in") handling, communicating with your backend over a clean, text-based WebSocket.
Start here
Ready to get started building with Conversation Relay? These resources get you from blinking cursor to talking AI.
- Conversation Relay onboarding - start here.
- Conversation Relay docs - the full reference for the WebSocket messages and TwiML.
- Voice configuration - pick TTS voices and languages.
Starter kits
Already have an LLM in mind, plus an API key with a lab or a third party provider? With these examples, add your API key and you're quickly chatting.
- OpenAI starter - Node.js
- Anthropic starter - Node.js
- Gemini starter - Python
If you’d like a more descriptive walkthrough – don’t worry, we’ve got you covered! These tutorials and video walk through how the starter kits are built.
- OpenAI - Part 1: Connect · Part 2: Token streaming and interruptions · Part 3: Tool calling
- Anthropic - Part 1: Connect · Part 2: Token streaming and interruptions · Part 3: Tool calling
- Google Gemini - Integrate Google Gemini with Twilio Voice using Conversation Relay
- Mistral - Build an AI agent with Conversation Relay and Mistral
Level up
Have a more advanced use case in mind, or want to see what it takes to run a Conversation Relay app in production? These posts show you more advanced Conversation Relay builds.
- Build a Low-latency Voice AI Agent with Guardrails on Twilio and AWS - build an inbound voice AI agent with AWS services and Conversation Relay that verifies callers, keeps identity out of the model and hands off to a person with full context
- Multilingual Conversation Relay - a sample repository which shows you how to switch languages in the middle of a call.
Media Streams
Media Streams gives you raw, bidirectional audio from a Programmable Voice call over WebSockets.
With Media Streams, Twilio steps out of the orchestration layer and acts strictly as a real-time audio pipe to your server.
- OpenAI -
- Build an inbound AI voice assistant with Media Streams and OpenAI
- Build an outbound AI voice assistant with Media Streams and OpenAI
- A minimalist integration
- Rime - Build an AI Voice Assistant with Twilio Voice and Media Streams, Rime's Prism, and Node.js
- NVIDIA - Real-time speech-to-speech with Media Streams and NVIDIA PersonaPlex
Elastic SIP Trunking
With Elastic SIP Trunking, Twilio handles phone number provisioning and global PSTN connectivity, routing calls straight to an external SIP URI with zero middleware in between.
Wrapping Up
When deciding how to build Voice AI with Twilio, the simplest rule is to pick the highest abstraction layer that doesn't block your core requirements.
For most teams, Twilio Agent Connect (TAC) is an excellent choice because it keeps your agent decoupled from telephony plumbing, lets you add other features covered by Twilio’s Conversations Suite, and gives you a clear path to scale beyond voice. If you want hands-on, token-by-token WebSocket control over a custom cascaded text LLM loop, build your application with Conversation Relay.
If you need raw audio access to bridge into a managed Voice AI engine or build a custom audio pipeline, use Media Streams. And if you're connecting a turnkey Voice AI vendor or a platform that speaks SIP natively, stick to Elastic SIP Trunking and keep your architecture lean.
Nathaniel leads the Developer Evangelism team at Twilio working to create magical moments for developers building customer experiences of the future. His life goals are to have Batman’s brains, Deadpool’s humour, T’Challa’s fashion sense, Killmonger’s Wokeness, and Thanos’ determination! He serves the Javascript community in the UK and the rest of Europe
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.