Skip to main content

xAI Realtime

XaiRealtime selects xAI’s Grok Voice Agent API (wss://api.x.ai/v1/realtime) as an end-to-end speech-to-speech engine. Pass it as the engine on phone.agent({...}) and Patter wires the audio stream straight through — no separate STT or TTS. xAI’s Voice Agent API is OpenAI-Realtime-GA-compatible: the same session.update / response.create / streaming-event flow works after swapping the base URL, the API key, and the model. Under the hood XaiRealtime reuses Patter’s GA realtime adapter and grafts on the xAI-specific session knobs (reasoning effort, language hint, keyterms, output speed, pronunciation replacements, session resumption, and server-side tools), so every feature gate in the call handler — barge-in, tool calling, heartbeat, transcode — fires for xAI with no per-provider branches.
Beta. The engine is validated against the xAI Voice Agent API spec; it has not yet been exercised against a live phone call.

Install

Set XAI_API_KEY in your environment (or pass apiKey).

Constructor

Usage

Pass the engine as the engine on phone.agent({...}):

Models

Pass a versioned name to pin a specific release; grok-voice-latest always points at the newest voice model.
ModelNotes
grok-voice-latest (default)Alias — currently resolves to grok-voice-think-fast-1.0. Use it so your app tracks the recommended model.
grok-voice-think-fast-1.0Flagship voice model. Reasoning is on by default (reasoningEffort: "high").
grok-voice-fast-1.0Legacy model — deprecated. Available for existing integrations; new apps should use grok-voice-latest.

Session options

All optional with safe defaults; unset knobs are omitted from the wire so xAI applies its own server defaults.
TypeScriptPythonDefaultNotes
apiKeyapi_keyReads XAI_API_KEY when omitted.
modelmodel"grok-voice-latest"See Models.
voicevoice"eve"Built-in or custom voice ID.
reasoningEffortreasoning_effort"high" enables reasoning (xAI server default); "none" disables it for lower latency.
vadThresholdvad_thresholdServer VAD activation threshold [0.1, 0.9] (xAI default 0.85). Higher requires louder audio to trigger.
silenceDurationMssilence_duration_msTrailing silence (ms) the VAD waits for before ending the user’s turn.
prefixPaddingMsprefix_padding_msAudio (ms) captured before detected speech start (xAI default 333).
idleTimeoutMsidle_timeout_msWhen set, the server re-engages the user after this many ms of silence following an assistant turn.
languageHintlanguage_hintBCP-47 code biasing input transcription toward one language (e.g. "es-MX").
keytermskeyterms[] / ()Up to 100 bias terms (≤50 chars each) for transcription.
speedspeedAssistant playback speed multiplier [0.7, 1.5].
replacereplacePronunciation map applied before TTS, e.g. { "Acme Mobile": "Acme Mobull" }. Only the spoken audio changes; the transcript keeps the original.
resumptionresumptionfalseOpt in to session resumption — the server caches conversation turns and replays them on reconnect.
serverToolsserver_tools[] / ()Raw xAI server-side tool objects — see Server-side tools.

Tool calling

Function tools declared on phone.agent({ tools: [...] }) work exactly as they do on OpenAI Realtime — Patter’s tool bridge forwards the model’s function calls and returns your results. The built-in transfer_call and end_call tools are auto-injected into every agent, so a Grok voice agent can hand off or hang up out of the box.

Server-side tools

serverTools / server_tools passes raw xAI tool objects through to session.tools verbatim — web_search, x_search, mcp, and file_search. These execute server-side at xAI; the client never handles their results, and xAI bills them separately from Patter’s per-minute metering.

Pronunciation replacements

Fix how the model pronounces brand names or domain terms with replace / replace — matched case-insensitively in the model’s output and swapped before TTS, so only the spoken audio changes:

Telephony audio

Over Twilio / Telnyx the engine inherits Patter’s GA-compatible audio path: it negotiates PCM-16-LE @ 24 kHz with xAI and transcodes to / from the carrier’s μ-law 8 kHz internally — you don’t configure any of this.
xAI also supports native G.711 (audio/pcmu @ 8 kHz), which would let telephony calls skip the transcode entirely. That is a flagged future optimization, not yet wired into this engine.

When to use xAI Realtime vs alternatives

Use xAI Realtime when…Use OpenAI Realtime when…Use Pipeline mode when…
You want Grok voices, on-by-default reasoning, and built-in server-side web_search / x_search.You need the broadest tool-calling ecosystem and OpenAI’s GA reasoning tiers.You need provider-by-provider control (e.g. DeepgramSTT + AnthropicLLM + XaiTTS).

Rates

xAI bills the Grok Voice Agent per minute of session audio (provider key xai_realtime), not per token:
ItemRate
Voice Agent session audio0.05/min(0.05 / min (3.00 / hr)
Text input messages$0.004 per conversation.item.createdocumented, not metered by Patter metrics v1
Override the metered rate per-project via new Patter({ pricing: { xai_realtime: { price: ... } } }). See Metrics for the full rate table.

Notes

  • Beta — the engine is spec-validated, not yet live-call-validated. Pin a versioned model (grok-voice-think-fast-1.0) in production for stability.
  • Caller transcript display (known Beta limitation). The adapter sets xAI’s input-transcription model (grok-transcribe), and xAI emits conversation.item.input_audio_transcription.updated events rather than OpenAI’s .completed. This first Beta release does not yet consume the .updated variant, so the caller-side transcript does not populate the transcript display. Audio, model responses, barge-in, and tool calling are unaffected — and the assistant-side transcript still flows; full caller-transcript support is a follow-up.
  • Reasoning is enabled by default. Set reasoningEffort: "none" to disable it for lower latency on simple flows.
  • serverTools results are billed by xAI and never surface to your client code.

What’s Next

Engines

All engines side by side.

OpenAI Realtime

The default engine.

Agents

System prompts, tools, first messages.

Tools

Function calling inside a realtime session.