Overview
GrokRealtimeLLMService provides real-time, multimodal conversation capabilities using xAI’s Grok Voice Agent API. It supports speech-to-speech interactions with integrated LLM processing, function calling, and advanced conversation management with low-latency response times.
Grok Realtime API Reference
Pipecat’s API methods for Grok Realtime integration
Example Implementation
Complete Grok Realtime conversation example
Async Tool Example
Grok with async function calling (cancel_on_interruption=False)
Grok Voice Documentation
Official xAI Grok Voice Agent API documentation
xAI Console
Access Grok models and manage API keys
Installation
To use Grok Realtime services, install the required dependencies:Prerequisites
xAI Account Setup
Before using Grok Realtime services, you need:- xAI Account: Sign up at xAI Console
- API Key: Generate a Grok API key from your account dashboard
- Model Access: Ensure access to Grok Voice Agent models
- Usage Limits: Configure appropriate usage limits and billing
Required Environment Variables
XAI_API_KEY: Your xAI API key for authentication
Key Features
- Real-time Speech-to-Speech: Direct audio processing with low latency
- Multilingual Support: Support for multiple languages
- Voice Activity Detection: Server-side VAD for automatic speech detection
- Function Calling: Seamless support for external functions and tool integration
- Multiple Voice Options: Various voice personalities available
- WebSocket Support: Real-time bidirectional audio streaming
Configuration
GrokRealtimeLLMService
str
required
xAI API key for authentication.
str
default:"wss://api.x.ai/v1/realtime"
WebSocket base URL for the Grok Realtime API. Override for custom deployments.
SessionProperties
default:"None"
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use
settings=GrokRealtimeLLMService.Settings(session_properties=...) instead.bool
default:"False"
Whether to start with audio input paused.
Settings
Runtime-configurable settings passed via thesettings constructor argument using GrokRealtimeLLMService.Settings(...). These can be updated mid-conversation with LLMUpdateSettingsFrame. See Service Settings for details.
NOT_GIVEN and None values are omitted, letting the service use its own
defaults. Only parameters that are explicitly set are included.SessionProperties
TurnDetection
Theturn_detection field in SessionProperties configures voice activity detection and turn management:
AudioConfiguration
Theaudio field in SessionProperties accepts an AudioConfiguration with input and output sub-configurations:
AudioInput (audio.input):
AudioOutput (
audio.output):
Grok PCM audio supports sample rates: 8000, 11025, 16000, 22050, 24000, 32000, 44100, and 48000 Hz.
InputAudioTranscription (
audio.input.transcription):
Built-in Tools
Grok provides several built-in tools in addition to custom function tools:Usage
Basic Setup
With Session Configuration
With Built-in Tools
Updating Settings at Runtime
Asession_properties delta replaces the stored SessionProperties whole, so fields it leaves unset (such as tools, turn detection, and transcription) fall back to their defaults. Copy the full session config and change the fields you need:
Methods
delete_conversation_item
conversation.item.delete event to the server.
Parameters:
item_id(str): ID of the conversation item to delete
force_message
force_message conversation item. The server automatically injects the response lifecycle, so no response.create call is needed.
Parameters:
text(str): Verbatim text to synthesize and play
set_audio_input_paused()
True) or resumes (False) sending input audio to the model.
Notes
- Model versioning: The default model
"grok-voice-latest"tracks xAI’s recommended Voice Agent. For stability, pin a specific version in settings (e.g.,model="grok-voice-think-fast-1.0"). - Audio format auto-configuration: If
audio.inputoraudio.outputis not set insession_properties, the service configures PCM for it using the pipeline’s sample rates, which must be one of the supported PCM rates. When you setaudio.inputoraudio.output(for example, fortranscriptionorspeed), set itsformattoo. Input audio is sent without resampling, so a configured input rate must match the pipeline’saudio_in_sample_rate. - Server-side VAD: Enabled by default. When VAD is enabled, the server handles speech detection and turn management automatically. Set
turn_detectiontoNonefor manual turn detection. - Audio flow timing: User audio flows once the session is configured, without waiting for a first context, so the user can speak first without an
LLMRunFrame. - Interruption handling: Interruptions send
response.cancelto stop in-flight assistant audio on the wire andconversation.item.truncateto align server-side history with what the user heard. With server VAD enabled, the input buffer is preserved (not cleared) so interrupting user speech remains intact. Manual turn mode clears the input buffer on interruption. - Voice IDs: Accepts any built-in voice ID from xAI’s catalogue or a custom voice ID from the Custom Voices API. Voice IDs are case-insensitive. Default is
"eve". - G.711 formats: PCMU and PCMA are fixed at 8000 Hz. The service passes audio through without converting it, and pipeline audio frames are 16-bit PCM, so use
PCMAudioFormat; for telephony, the transport’s serializer converts to and from G.711. - System instruction precedence: The
system_instructionfrom service settings takes precedence over an initial system message in the LLM context. A warning is logged when both are set. - Async tool support: Functions registered with
cancel_on_interruption=Falseare supported. The final tool result is delivered via the formal tool-result channel once the async function completes. Intermediate results (is_final=False) reach the model as conversation messages.