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 api_key).

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.

Session options

All optional with safe defaults; unset knobs are omitted from the wire so xAI applies its own server defaults.

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

server_tools / serverTools 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 — 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

Rates

xAI bills the Grok Voice Agent per minute of session audio (provider key xai_realtime), not per token: Override the metered rate per-project via 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 reasoning_effort="none" to disable it for lower latency on simple flows.
  • server_tools 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.