> ## Documentation Index
> Fetch the complete documentation index at: https://visionagents.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Phone Calling

Connect Vision Agents to PSTN phone calls. A telephony provider handles the phone network; your FastAPI server receives webhooks, streams audio over WebSocket, and bridges it into a Stream call where your agent runs.

> [!NOTE]
>
> Vision Agents uses [Stream Video](https://getstream.io/video/) for real-time WebRTC transport by default. [External WebRTC transports](https://visionagents.ai/integrations/introduction-to-integrations.md#edge-transport) are supported as well. Most AI providers offer free tiers to get started.

## Choose a provider

> [card] [Twilio](https://visionagents.ai/integrations/telephony/twilio.md)
>
> Media Streams, TwiML, built-in webhook helpers — default in our examples

> [card] [Telnyx](https://visionagents.ai/integrations/telephony/telnyx.md)
>
> Call Control API, bidirectional media streaming

## How phone agents work

Every phone integration follows the same pattern, regardless of provider:

1. **Webhook** — the provider notifies your server of an incoming call (or you initiate an outbound call via REST API)
2. **Register** — create a call entry in a provider registry with a secret token
3. **Stream URL** — tell the provider to open a WebSocket media stream to your server
4. **Bridge** — `attach_phone_to_call` connects phone audio ↔ a Stream call where your agent listens and responds

```mermaid theme={null}
flowchart LR
    subgraph twilio [Twilio]
        T1[Voice webhook] --> T2[TwiML Connect Stream]
        T2 --> T3[Media Streams WS]
    end
    subgraph telnyx [Telnyx]
        X1[Call Control webhook] --> X2[Answer or Dial API]
        X2 --> X3[Media Streaming WS]
    end
    T3 --> Bridge[attach_phone_to_call]
    X3 --> Bridge
    Bridge --> Stream[Stream call plus Agent]
```

## Shared building blocks

Both telephony plugins expose the same core primitives:

| Building block | Role |
| - | - |
| Call registry | Tracks active calls, assigns tokens, optional async `prepare` to warm up the agent |
| Media stream | WebSocket handler that receives/sends phone audio |
| `attach_phone_to_call` | Bridges provider audio ↔ Stream WebRTC participant |
| Tokenized media URL | Provider connects to `wss://<host>/<provider>/media/{call_id}/{token}` |

Provider-specific differences:

| | Twilio | Telnyx |
| - | - | - |
| Answer mechanism | Return TwiML with `<Stream>` | Call Control Answer/Dial API with `stream_url` |
| Webhook auth | `verify_twilio_signature` (built-in) | Ed25519 verification (see plugin examples) |
| Audio encoding | mulaw 8 kHz | PCMU/PCMA 8 kHz or L16 16 kHz |

## Prerequisites

Before starting any phone example:

* [Stream](https://getstream.io/try-for-free/) API key and secret
* A telephony provider account with at least one phone number
* [ngrok](https://ngrok.com/) (or another HTTPS tunnel) for local development
* A public webhook URL pointing at your FastAPI server

> [!TIP]
>
> **Prefer managed hosting?** [Stream Voice AI](https://getstream.io/video/voice-ai/) runs production voice agents on Stream's global edge, phone numbers, web and mobile clients, co-located STT/LLM/TTS, and built-in observability. [Join the waitlist](https://getstream.io/video/voice-ai/) for early access.

## Learning path

Follow this order:

1. **[Twilio Phone Agent](https://visionagents.ai/examples/twilio-phone-agent.md)** — get your first inbound and outbound call working
2. **[Phone Support Agent (RAG)](https://visionagents.ai/examples/phone-and-rag.md)** — add knowledge retrieval on top
3. **[Twilio](https://visionagents.ai/integrations/telephony/twilio.md)** or **[Telnyx](https://visionagents.ai/integrations/telephony/telnyx.md)** integration pages — API reference when building your own server

> [card] [Twilio Phone Agent](https://visionagents.ai/examples/twilio-phone-agent.md)
>
> Step-by-step phone tutorial

> [card] [Phone Support Agent (RAG)](https://visionagents.ai/examples/phone-and-rag.md)
>
> Add knowledge retrieval to calls

## Quick orientation

**1. Expose your local server**

Run `ngrok http 8000` and note the HTTPS hostname for `NGROK_URL`.

**2. Point webhooks at your server**

Configure your provider to send call events to your FastAPI endpoints (e.g. `https://<NGROK_URL>/twilio/voice` for Twilio).

**3. Run an example and call your number**

Follow the [Twilio Phone Agent](https://visionagents.ai/examples/twilio-phone-agent.md) tutorial for full commands. Dial your Twilio number to verify end-to-end audio.

## Next Steps

> [card] [Twilio Integration](https://visionagents.ai/integrations/telephony/twilio.md)
>
> Plugin API reference

> [card] [Telnyx Integration](https://visionagents.ai/integrations/telephony/telnyx.md)
>
> Alternative provider

> [card] [RAG for Agents](https://visionagents.ai/guides/rag.md)
>
> Knowledge retrieval backends

> [card] [Stream Video RTC](https://visionagents.ai/integrations/edge-transport/getstream.md)
>
> Default edge transport

> [card] [Build a Voice Agent](https://visionagents.ai/introduction/voice-agents.md)
>
> Voice agent fundamentals


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.