Skip to main content

SpaceXAI Grok Voice Agent API

How to use SpaceXAI's Grok Voice Agent API with LiveKit Agents.

Use in Agent Builder

Create a new agent in your browser using this model

Overview

The Grok Voice Agent API  enables low-latency, two-way voice interactions using Grok models. The Grok Voice Agent API is compatible with OpenAI's Realtime API. It's available in LiveKit Agents through LiveKit Inference and the SpaceXAI plugin. With LiveKit Inference, you use your LiveKit Cloud credentials instead of a separate SpaceXAI API key, and LiveKit Cloud bills you for usage. Use the plugin instead if you want to manage your own billing.

LiveKit Inference

Use LiveKit Inference to access Grok Voice Agent models without a separate SpaceXAI API key. The following table lists the SpaceXAI realtime models available through LiveKit Inference.

A checkmark in the EU endpoint column means the model has a dedicated EU endpoint, in addition to the global endpoint. To learn more, see Data residency.

Model nameModel IDTypeEU endpoint
Grok Voice 3.0
xai/grok-voice-3.0
Turn-basedNo EU endpoint

Usage

Use the RealtimeModel class from the inference module to run Grok Voice Agent models through LiveKit Inference. You can use this model in the Voice AI quickstart:

from livekit.agents import AgentSession, inference
session = AgentSession(
llm=inference.RealtimeModel(model="xai/grok-voice-3.0", voice="eve"),
)
import { AgentSession, inference } from '@livekit/agents';
const session = new AgentSession({
llm: new inference.RealtimeModel({ model: 'xai/grok-voice-3.0', voice: 'eve' }),
});

Authentication uses your LiveKit Cloud credentials. Set LIVEKIT_API_KEY and LIVEKIT_API_SECRET in your .env file, or pass api_key and api_secret directly. In Node.js, these parameters are apiKey and apiSecret.

Parameters

The following are the main parameters for configuring Grok Voice Agent models with LiveKit Inference. For a complete list, see the Python API reference.

model
Required
string

The model to use. Must be a SpaceXAI model ID from the models list, including the xai/ prefix.

voicestringDefault: 'eve'

Voice to use for speech generation. The default is eve. For a list of available voices, see Available voices .

turn_detectionTurnDetection | None

Configuration for turn detection. LiveKit Inference enables server VAD by default with the following settings: threshold=0.5, prefix_padding_ms=300, silence_duration_ms=200. For more information, see Turn detection.

In Node.js, use turnDetection.

input_audio_transcriptionAudioTranscription | None

Configuration for transcribing user audio. LiveKit Inference uses the grok-transcribe model by default.

In Node.js, use inputAudioTranscription.

api_keystring

LiveKit API key. Defaults to the LIVEKIT_API_KEY environment variable.

In Node.js, use apiKey.

api_secretstring

LiveKit API secret. Defaults to the LIVEKIT_API_SECRET environment variable.

In Node.js, use apiSecret.

String descriptors

As a shortcut, you can also pass the model ID directly to the llm argument in your AgentSession:

from livekit.agents import AgentSession
session = AgentSession(
llm="xai/grok-voice-3.0",
)
import { AgentSession } from '@livekit/agents';
const session = new AgentSession({
llm: 'xai/grok-voice-3.0',
});

Plugin

Use the SpaceXAI plugin to connect directly to the Grok Voice Agent API with your own API key. The plugin includes a RealtimeModel class for building voice agents.

Installation

Install the SpaceXAI plugin:

uv add "livekit-agents[xai]~=1.8"
pnpm add "@livekit/agents-plugin-xai@1.x"

Authentication

The SpaceXAI plugin requires a SpaceXAI API key .

Set XAI_API_KEY in your .env file.

Usage

Use the Grok Voice Agent API within an AgentSession. For example, you can use it in the Voice AI quickstart.

from livekit.agents import AgentSession
from livekit.plugins import xai
session = AgentSession(
llm=xai.realtime.RealtimeModel(voice="Ara"),
)
import { voice } from '@livekit/agents';
import * as xai from '@livekit/agents-plugin-xai';
const session = new voice.AgentSession({
llm: new xai.realtime.RealtimeModel({ voice: "Ara" }),
});

Parameters

This section describes some of the available parameters. For a complete reference of all available parameters, see the plugin reference links in the Additional resources section.

modelstrDefault: 'grok-voice-latest'

Model ID for the Grok Voice Agent API. The default is grok-voice-latest in Python and grok-voice-think-fast-1.0 in Node.js. For the full list, see the SpaceXAI documentation .

voicestrDefault: 'ara'

Voice to use for speech generation. For a list of available voices, see Available voices .

api_key
Required
strEnv: XAI_API_KEY

SpaceXAI API key.

turn_detectionTurnDetection | None

Configuration for turn detection. Server VAD is enabled by default with the following settings: threshold=0.5, prefix_padding_ms=300, silence_duration_ms=200.

Tools

Note

ProviderTools are only available in Python.

SpaceXAI supports provider tools that enable the model to use built-in capabilities executed on the model server. These tools can be used alongside function tools defined in your agent's codebase.

Available tools include:

  • XSearch: Perform keyword search, semantic search, user search, and thread fetch on X
  • WebSearch: Search the web and browse pages
  • FileSearch: Search uploaded knowledge bases (collections ) on SpaceXAI

For example, the following code shows an agent that retrieves top trending topics and passes them to a function tool for summarization.

from livekit.agents import Agent, AgentSession, RunContext
from livekit.plugins import xai
class MyAgent(Agent):
def __init__(self):
super().__init__(
instructions="you are an AI assistant that have the capability of searching X",
llm=xai.realtime.RealtimeModel(),
tools=[xai.realtime.XSearch()],
)
@function_tool
async def summarize_trending_topics(self, context: RunContext, topics: list[str]) -> str:
"""Summarizes the trending topics, which are provided by other tools.
Args:
topics: The trending topics on X
"""
if len(topics) > 3:
topics = topics[:3]
return f"The top three topics are: {topics}"

Turn detection

The Grok Voice Agent API includes built-in VAD-based turn detection, enabled by default with optimized settings:

from livekit.agents import AgentSession, inference
from openai.types.realtime.realtime_audio_input_turn_detection import ServerVad
session = AgentSession(
llm=inference.RealtimeModel(
model="xai/grok-voice-3.0",
turn_detection=ServerVad(
type="server_vad",
threshold=0.5,
prefix_padding_ms=300,
silence_duration_ms=200,
create_response=True,
interrupt_response=True,
),
),
)
import { AgentSession, inference } from '@livekit/agents';
const session = new AgentSession({
llm: new inference.RealtimeModel({
model: 'xai/grok-voice-3.0',
turnDetection: {
type: 'server_vad',
threshold: 0.5,
prefix_padding_ms: 300,
silence_duration_ms: 200,
create_response: true,
interrupt_response: true,
},
}),
});
from livekit.agents import AgentSession
from livekit.plugins import xai
from openai.types.beta.realtime.session import TurnDetection
session = AgentSession(
llm=xai.realtime.RealtimeModel(
turn_detection=TurnDetection(
type="server_vad",
threshold=0.5,
prefix_padding_ms=300,
silence_duration_ms=200,
create_response=True,
interrupt_response=True,
)
),
)
import { voice } from '@livekit/agents';
import * as xai from '@livekit/agents-plugin-xai';
const session = new voice.AgentSession({
llm: new xai.realtime.RealtimeModel({
turnDetection: {
type: 'server_vad',
threshold: 0.5,
prefix_padding_ms: 300,
silence_duration_ms: 200,
create_response: true,
interrupt_response: true,
},
}),
});
  • threshold — higher values require louder audio to activate, better for noisy environments.
  • prefix_padding_ms — amount of audio to include before detected speech.
  • silence_duration_ms — duration of silence to detect speech stop (shorter = faster turn detection).

Additional resources

The following resources provide more information about using SpaceXAI with LiveKit Agents.