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

# xAI

> Use the xAI text-to-speech plugin in a Zero Runtime pipeline. Setup and usage in Python and JavaScript.

xAI is a **text-to-speech** plugin. It streams Grok voices and supports inline expression tags like `[laugh]` and `<whisper>` in the text.

## Setup

Set your xAI API key in the worker environment. Generate a key from the [xAI site](https://console.x.ai):

```bash theme={null}
export XAI_API_KEY=<key>
```

## Usage

Import the plugin and pass it to the pipeline's `tts` slot.

```python Python theme={null}
from zeroruntime.plugins import XAITTS

tts = XAITTS()

# Pipeline(tts=tts, ...)
```

```typescript Node JS theme={null}
import { XAITTS } from '@zeroruntime/js-sdk/plugins';

const tts = XAITTS();

// Pipeline({ tts, ... })
```

## Parameters

*Constructor parameters for `XAITTS`.*

| Parameter | Type | Default | Description |
| - | - | - | - |
| `api_key` | `str` | `None` | xAI API key. Falls back to the `XAI_API_KEY` environment variable when unset. |
| `voice` | `str` | `"eve"` | Built-in voice ("eve", "ara", "rex", "sal", "leo") or a custom voice ID. |
| `language` | `str` | `"en"` | BCP-47 language code, e.g. "en", "fr" or "pt-BR", or "auto" to detect the language from the text. |
| `codec` | `Literal['pcm', 'mulaw']` | `"pcm"` | Audio encoding of the generated speech: "pcm" (16-bit linear) or "mulaw". |
| `sample_rate` | `int` | `24000` | Output sample rate in Hz: 8000, 16000, 22050, 24000, 44100 or 48000. |
| `optimize_streaming_latency` | `int` | `0` | 0 for best quality, or 1 for faster time-to-first-audio with a slight quality tradeoff. |
| `text_normalization` | `bool` | `False` | Convert numbers, abbreviations and symbols into spoken words before synthesis. |
| `base_url` | `str` | `"wss://api.x.ai/v1/tts"` | WebSocket URL of the xAI text-to-speech endpoint. |
| `max_connection_age_sec` | `float` | `300.0` | Seconds after which the streaming connection is reopened, to stay within xAI session limits. |

## Import paths

| SDK | Import | Constructor |
| - | - | - |
| Python | `from zeroruntime.plugins import XAITTS` | `XAITTS()` |
| Node JS | `import { XAITTS } from '@zeroruntime/js-sdk/plugins'` | `XAITTS()` |

Synthesized audio is streamed back to the caller after the [LLM](https://docs.zeroruntime.ai/runtime-sdk/plugins/overview.md) produces a response.


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