Skip to main content

xAI STT

XaiSTT streams raw audio to xAI’s real-time Speech-to-Text WebSocket (wss://api.x.ai/v1/stt) and yields Patter transcript events. Configuration is carried entirely in the URL query string — there is no setup message — and audio is sent as raw binary frames (no base64). The adapter waits for the server’s transcript.created event before it declares the connection ready, then maps xAI’s is_final / speech_final flags onto Patter’s interim / chunk-final / utterance-final semantics, the same two-flag scheme Deepgram uses. The module also exports a one-shot batch helper — xai_transcribe (Python) / xaiTranscribe (TypeScript) — that wraps the REST endpoint (POST https://api.x.ai/v1/stt) for file or URL transcription with word timestamps.
Beta. The adapter is validated against the xAI STT API spec; it has not yet been exercised against a live phone call.

Install

The Python adapter uses aiohttp (pulled in by the [xai] extra). The TypeScript adapter uses the ws package and the platform fetch — no vendor SDK.

Authentication

Both the streaming and batch endpoints authenticate with an Authorization: Bearer <key> header. XAI_API_KEY is read automatically when api_key / apiKey is omitted.

Usage

Use the namespaced import (getpatter.stt.xai) or the flat re-export (XaiSTT). Both auto-resolve XAI_API_KEY from the environment when api_key is omitted.
Plug it into an agent:

Streaming transcript semantics

xAI emits transcript.partial events whose is_final / speech_final flags map onto the transcript states the pipeline reacts to: A trailing transcript.done (after close() sends audio.done) surfaces any remaining text as a final. error frames are logged and do not close the connection. The adapter exposes finalize(), which sends {"type": "finalize"} to force the current utterance to speech_final immediately. The pipeline’s VAD speech-end fast-path duck-types this — without it every turn waits out the full endpointing delay.

Smart Turn end-of-turn detection

Set smart_turn / smartTurn to a confidence threshold in [0.0, 1.0] to enable xAI’s Smart Turn ML end-of-turn model instead of relying on silence-based endpointing alone. The threshold trades responsiveness against interruption safety: Pair it with smart_turn_timeout_ms / smartTurnTimeoutMs ([1, 5000]) to force speech_final after that much silence even when the model is undecided.

Keyterms and diarization

Bias transcription toward domain vocabulary (product names, proper nouns) with up to 100 key terms (≤50 chars each), and turn on speaker diarization so each word carries a speaker index:

Languages

Pass a language code to language to enable server-side text formatting (Inverse Text Normalization) for that language. xAI supports 25 codes for the streaming endpoint:

Encodings and sample rate

encoding accepts pcm (default), mulaw, or alaw. The default pcm @ sample_rate=16000 matches what Patter’s pipeline feeds every STT stage (the carrier bridge decodes inbound μ-law to linear PCM16 @ 16 kHz on both Twilio and Telnyx), so XaiSTT drops in without transcoding. Set mulaw / alaw @ 8000 only when feeding raw carrier audio directly.

Rates

xAI bills STT by audio duration. Patter meters the streaming rate on the pipeline (provider key xai): Override the metered rate per-project via Patter(pricing={"xai": {"price": ...}}). See Metrics for the full rate table.

Options

Batch transcription

For a one-shot file or URL (rather than a live stream), use the batch helper. Pass either raw audio bytes or a url for xAI to download server-side. Container formats (WAV/MP3/OGG/Opus/FLAC/AAC/MP4/M4A/MKV) are auto-detected; for raw headerless audio pass audio_format (pcm / mulaw / alaw) and sample_rate. Set format=True (with language) for Inverse Text Normalization (“one hundred dollars” → “$100”).
The helper returns a parsed result — XaiTranscription(text, language, duration, words) — where each XaiWord carries text, start, end, and (when diarize is on) speaker.

Low-level usage

The pipeline-mode wrapper adds XAI_API_KEY resolution on top of the underlying provider. To use the provider directly, import it from getpatter.providers.xai_stt:

What’s Next

STT

All STT providers side by side.

xAI TTS

Grok text-to-speech.

xAI Realtime

Grok Voice Agent engine.

Metrics

Cost tracking and rates.