telnyx plugin bridges PSTN phone calls into a Vision Agents + Stream call through Telnyx Call Control webhooks and bidirectional Media Streaming.
Vision Agents requires a Stream account
for real-time transport.
What the plugin provides
- Call Control webhook handling pattern (via your FastAPI server)
- Bidirectional Telnyx Media Streaming over WebSocket
CallRegistryfor call/session/token trackingattach_phone_to_callto bridge Telnyx audio ↔ Stream WebRTC- Audio conversion: PCMU, PCMA (8 kHz), L16 (16 kHz)
Prerequisites
| Requirement | Notes |
|---|---|
| Telnyx account + API key | TELNYX_API_KEY |
| Telnyx phone number (E.164) | TELNYX_PHONE_NUMBER |
| Call Control App | Required — a forwarding-only number connection is not enough |
| Webhook public URL | ngrok for local dev → https://<NGROK_URL>/telnyx/events |
| Webhook signature key | TELNYX_PUBLIC_KEY (Base64 Ed25519 from Mission Control Portal) |
| Stream credentials | STREAM_API_KEY, STREAM_API_SECRET |
Installation
Environment Variables
| Variable | Required | Description |
|---|---|---|
TELNYX_API_KEY | Yes | Telnyx API key for Call Control / Dial |
TELNYX_PUBLIC_KEY | Yes (production) | Ed25519 public key for webhook signature verification |
TELNYX_PHONE_NUMBER | Yes | Caller ID / inbound number in E.164 |
NGROK_URL | Local dev | Public hostname without https:// |
TELNYX_CALL_CONTROL_APP_ID | Manual setup | Existing Call Control App ID (skip if using example --setup-telnyx) |
TELNYX_PHONE_NUMBER_ID | Inbound manual | Telnyx phone number resource ID |
STREAM_API_KEY / STREAM_API_SECRET | Yes | Stream edge transport |
Telnyx account setup
Quick local dev (--setup-telnyx) — the plugin examples auto-create a temporary Call Control App, set the webhook URL, route the inbound number, and clean up on shutdown.
Manual setup:
- Create a Telnyx Call Control App.
- Set the app webhook URL to
https://<NGROK_URL>/telnyx/events. - Route your inbound phone number to that Call Control App.
- For outbound calls, ensure the app has an outbound voice profile for your target country. On restricted accounts, verify destination numbers before dialing.
Quick Start
The plugin gives you registry, media stream, and bridge primitives. Your FastAPI server wires them to Telnyx webhooks and WebSockets:Inbound calls
Telnyx sends webhooks toPOST /telnyx/events. On call.initiated with direction incoming, register the call and answer with a media stream URL:
Outbound calls
Pre-register the call in the registry, start your server, then dial via the Telnyx Call Control API withconnection_id set to your Call Control App ID:
Key Components
| Component | Description |
|---|---|
TelnyxCallRegistry / CallRegistry | Tracks active calls, tokens, optional async prepare tasks |
TelnyxCall | Call session with from_number, to_number, await_prepare() |
TelnyxMediaStream / MediaStream | WebSocket media handler; exposes audio_track, send_audio(), run() |
attach_phone_to_call | Bridges Telnyx RTP audio ↔ Stream call participant |
| Audio helpers | pcmu_to_pcm, pcm_to_pcmu, pcm_to_pcma, l16_to_pcm, etc. |
Audio formats
| Encoding | Sample rate | Direction |
|---|---|---|
| PCMU / PCMA | 8 kHz | Default inbound; outbound with bidirectional RTP |
| L16 | 16 kHz | Bidirectional when configured |
stream_bidirectional_mode=rtp.
| Constant | Default | Description |
|---|---|---|
TELNYX_DEFAULT_SAMPLE_RATE | 8000 | PCMU/PCMA rate |
TELNYX_L16_SAMPLE_RATE | 16000 | L16 bidirectional rate |
Common setup errors
| Error | Fix |
|---|---|
Invalid connection_id | Check Call Control App ID is set and active |
| Webhook URL mismatch | Update the app webhook to your current ngrok URL, or use --setup-telnyx |
| Inbound number not routed | Assign the Telnyx number to the Call Control App |
| Destination not verified | Verify the --to number in Telnyx, or use an unrestricted account |
Next Steps
Telnyx Plugin Examples
Minimal inbound and outbound phone examples
Phone Calling
Provider overview and learning path
Twilio
Alternative telephony provider
Stream Video RTC
Default edge transport for agent calls
RAG for Agents
Add knowledge base to phone agents
Build a Voice Agent
Get started with voice