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 — xaiTranscribe (TypeScript) / xai_transcribe (Python) — 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
ws package and the platform fetch — no vendor SDK. The Python adapter uses aiohttp (pulled in by the [xai] extra).
Authentication
Authorization: Bearer <key> header. XAI_API_KEY is read automatically when apiKey / api_key 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
apiKey is omitted.Streaming transcript semantics
xAI emitstranscript.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() (Python 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
SetsmartTurn / smart_turn 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
smartTurnTimeoutMs / smart_turn_timeout_ms ([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 aspeaker index:
Languages
Pass a language code tolanguage 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 @ sampleRate=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 keyxai):
Override the metered rate per-project via
new 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 rawaudio 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 audioFormat (pcm / mulaw / alaw) and sampleRate. Set format: true (with language) for Inverse Text Normalization (“one hundred dollars” → “$100”).
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 addsXAI_API_KEY resolution on top of the underlying provider. To use the provider directly, import it and pass the API key as the first argument:
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.

