> ## 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 speech-to-text plugin in a Zero Runtime pipeline. Setup and usage in Python and JavaScript.

xAI is a **speech-to-text** plugin. It streams transcripts with support for interim results, speaker diarization, and multichannel audio.

## 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 `stt` slot.

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

stt = XAISTT()

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

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

const stt = XAISTT();

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

## Parameters

*Constructor parameters for `XAISTT`.*

| Parameter | Type | Default | Description |
| - | - | - | - |
| `api_key` | `str` | `None` | xAI API key. Falls back to the `XAI_API_KEY` environment variable when unset. |
| `sample_rate` | `int \| None` | `None` | Sample rate of incoming audio in Hz: 8000, 16000, 22050, 24000, 44100 or 48000. Leave unset to detect it automatically. |
| `encoding` | `Literal['pcm', 'mulaw', 'alaw']` | `"pcm"` | Encoding of incoming audio: "pcm" (16-bit linear), "mulaw" or "alaw". |
| `interim_results` | `bool` | `True` | Emit partial transcripts while the user is still speaking, before the final result. |
| `endpointing` | `int` | `50` | Milliseconds of silence before an utterance is finalized, 0 to 5000. Keep it low for fast turn-taking. |
| `language` | `str \| None` | `"en"` | BCP-47 language code, e.g. "en" or "fr". Any supported language is transcribed; this enables written-form numbers and currencies. |
| `diarize` | `bool` | `False` | Label each transcribed word with the speaker who said it. |
| `multichannel` | `bool` | `False` | Transcribe each audio channel separately instead of mixing down to mono. |
| `channels` | `int` | `2` | Number of audio channels to transcribe when multichannel is on, 2 to 8. Ignored otherwise. |
| `base_url` | `str` | `"wss://api.x.ai/v1/stt"` | WebSocket URL of the xAI speech-to-text endpoint. |
| `model` | `str \| None` | `None` | Transcription model, e.g. "grok-voice-transcribe-1.0". Leave unset to use xAI's standard model. Python only. |

## Import paths

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

Transcribed text passes to the [LLM](https://docs.zeroruntime.ai/runtime-sdk/plugins/overview.md) once [turn detection](https://docs.zeroruntime.ai/runtime-sdk/plugins/turn-detection.md) decides the caller has finished speaking.


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