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

# Text-to-Speech REST API examples

> Code examples for the Telnyx Text-to-Speech REST API showing OpenAI SDK compatibility, synchronous and streaming playback, and async retrieval.

## OpenAI SDK Compatibility

The REST endpoint is a drop-in replacement for the OpenAI Audio API:

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_TELNYX_API_KEY",
    base_url="https://api.telnyx.com/v2"
)

response = client.audio.speech.create(
    model="tts-1-hd",
    voice="astra",
    input="Hello from Telnyx."
)

response.stream_to_file("output.mp3")
```
