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

# Telnyx Frame Serializer

> TelnyxFrameSerializer integrates Pipecat with Telnyx's WebSocket media streaming protocol for telephony bots.

## Overview

`TelnyxFrameSerializer` enables integration with Telnyx's WebSocket media streaming protocol, allowing your Pipecat application to handle phone calls via Telnyx's voice services with bidirectional audio conversion, DTMF event handling, and support for multiple audio encodings.

> [card] [Telnyx Serializer API Reference](https://reference-server.pipecat.ai/en/latest/api/pipecat.serializers.telnyx.html)
>
> Pipecat's API methods for Telnyx WebSocket integration

> [card] [Example Implementation](https://github.com/pipecat-ai/pipecat-examples/tree/main/telnyx-chatbot)
>
> Complete telephony examples with Telnyx

> [card] [Telnyx Documentation](https://developers.telnyx.com/docs/voice/programmable-voice/voice-api-fundamentals)
>
> Official Telnyx media streaming documentation

> [card] [Telnyx Portal](https://portal.telnyx.com/)
>
> Manage phone numbers and streaming configuration

## Installation

The `TelnyxFrameSerializer` does not require any additional dependencies beyond the core Pipecat library:

```bash theme={null}
uv add "pipecat-ai"
```

## Prerequisites

### Telnyx Account Setup

Before using TelnyxFrameSerializer, you need:

1. **Telnyx Account**: Sign up at [Telnyx Portal](https://portal.telnyx.com/)
2. **Phone Number**: Purchase a Telnyx phone number with voice capabilities
3. **Media Streaming**: Configure your phone number for WebSocket streaming
4. **Webhook Configuration**: Set up webhook endpoints for call handling

### Required Environment Variables

* `TELNYX_API_KEY`: Your Telnyx API key for authentication and call control

### Required Configuration

* **Stream ID**: Provided by Telnyx during WebSocket connection
* **Audio Encodings**: Configure inbound/outbound encodings (PCMU, PCMA)
* **Call Control ID**: Required for automatic call termination (optional)

### Key Features

* **Bidirectional Audio**: Convert between Pipecat and Telnyx audio formats
* **DTMF Handling**: Process touch-tone events from callers
* **Auto Hang-up**: Terminate calls via Telnyx's REST API
* **Multiple Encodings**: Support for PCMU and PCMA audio formats

## Configuration

**stream\_id** `str` *required*

The Telnyx Stream ID.

**outbound\_encoding** `str` *required*

The encoding type for outbound audio received from Telnyx (e.g., `"PCMU"`,
`"PCMA"`).

**inbound\_encoding** `str` *required*

The encoding type for inbound audio sent to Telnyx (e.g., `"PCMU"`, `"PCMA"`).

**call\_control\_id** `str` (default: None)

The Telnyx Call Control ID. Required when `auto_hang_up` is enabled.

**api\_key** `str` (default: None)

Telnyx API key. Required when `auto_hang_up` is enabled.

**params** `InputParams` (default: None)

Configuration parameters for audio and hang-up behavior. See
[InputParams](#inputparams) below.

### InputParams

| Parameter | Type | Default | Description |
| - | - | - | - |
| `telnyx_sample_rate` | `int` | `8000` | Sample rate used by Telnyx (Hz). |
| `sample_rate` | `int` | `None` | Optional override for pipeline input sample rate. When `None`, uses the pipeline's configured rate. |
| `inbound_encoding` | `str` | `"PCMU"` | Audio encoding for data sent to Telnyx. |
| `outbound_encoding` | `str` | `"PCMU"` | Audio encoding for data received from Telnyx. |
| `auto_hang_up` | `bool` | `True` | Whether to automatically terminate the call on `EndFrame` or `CancelFrame`. |
| `resampler_clear_after_secs` | `float \| None` | `0.2` | Seconds of inactivity after which the stream resampler clears its internal history to avoid audio artefacts. Set to `None` to never clear (recommended for telephony providers with irregular gaps). |

## Usage

### Basic Setup

```python theme={null}
import os

from pipecat.serializers.telnyx import TelnyxFrameSerializer
from pipecat.transports.websocket.fastapi import (
    FastAPIWebsocketParams,
    FastAPIWebsocketTransport,
)

serializer = TelnyxFrameSerializer(
    stream_id=stream_id,
    outbound_encoding="PCMU",
    inbound_encoding="PCMU",
    call_control_id=call_control_id,
    api_key=os.getenv("TELNYX_API_KEY"),
)

transport = FastAPIWebsocketTransport(
    websocket=websocket,
    params=FastAPIWebsocketParams(
        audio_in_enabled=True,
        audio_out_enabled=True,
        add_wav_header=False,
        serializer=serializer,
    )
)
```

### Without Auto Hang-up

```python theme={null}
serializer = TelnyxFrameSerializer(
    stream_id=stream_id,
    outbound_encoding="PCMU",
    inbound_encoding="PCMU",
    params=TelnyxFrameSerializer.InputParams(
        auto_hang_up=False,
    ),
)
```

## Notes

* **Multiple audio encodings**: The serializer supports PCMU (mu-law) and PCMA (A-law) encodings. Any other value raises `ValueError` when the first audio is sent or received. The `inbound_encoding` and `outbound_encoding` must be specified as constructor arguments and will override any values set in `InputParams`.
* **Auto hang-up requires credentials**: When `auto_hang_up` is enabled (the default), you must provide `call_control_id` and `api_key`. A `ValueError` is raised at initialization if any are missing.
* **DTMF support**: Touch-tone digit events from callers are converted to `InputDTMFFrame` objects.


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