Skip to main content
Twilio is a programmable telephony provider. The twilio plugin bridges PSTN phone calls into a Vision Agents + Stream call through Twilio voice webhooks, TwiML Media Streams, and bidirectional WebSocket audio.
Vision Agents uses Stream Video for real-time WebRTC transport by default. External WebRTC transports are supported as well. Most AI providers offer free tiers to get started.

What the plugin provides

  • Twilio Media Streams over WebSocket with bidirectional audio
  • TwilioCallRegistry for call/session/token tracking
  • attach_phone_to_call to bridge Twilio mulaw audio ↔ Stream WebRTC
  • Built-in FastAPI helpers: verify_twilio_signature, CallWebhookInput, TwiML response builders
  • Automatic mulaw/PCM conversion at 8 kHz

Prerequisites

Installation

Or install the plugin package directly:

Environment Variables

Twilio account setup

  1. Buy or assign a Twilio phone number.
  2. Under Phone Numbers → Manage → Active numbers, open your number.
  3. Set A call comes in to Webhook pointing at:
  4. Use HTTP POST.
For a full walkthrough with copy-paste commands, see the Twilio Phone Agent example.

Quick Start

The plugin gives you registry, media stream, and bridge primitives. Your FastAPI server wires them to Twilio webhooks and WebSockets:

Inbound calls

Twilio sends a webhook when someone calls your number. Validate the signature, register the call, and return TwiML to start the media stream:
When running behind ngrok, add ProxyHeadersMiddleware so Twilio signature validation sees the public HTTPS URL. See the phone agent example source.

Outbound calls

Pre-register the call in the registry, start your server, then dial via the Twilio REST API:
The WebSocket media handler is the same as inbound.

Key Components

Audio

Twilio Media Streams use mulaw encoding at 8 kHz. The plugin converts between mulaw and PCM automatically in TwilioMediaStream and exposes conversion helpers if you need them directly.

Common setup errors

Next Steps

Twilio Phone Agent

Step-by-step inbound and outbound phone tutorial

Phone Support Agent (RAG)

Add knowledge retrieval to phone calls

Phone Calling

Provider overview and learning path

Telnyx

Alternative telephony provider

Stream Video RTC

Default edge transport for agent calls

Build a Voice Agent

Get started with voice