LiveKit docs › Partner spotlight › xAI › Grok Voice Agent API

---

# xAI Grok Voice Agent API plugin

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

Available in:
- [x] Node.js
- [x] Python

- **[Use in Agent Builder](https://cloud.livekit.io/projects/p_/agents/builder/new?llm=xai%2Fgrok-4-1-fast-non-reasoning&tts=xai%2Fgrok-4-1-fast-non-reasoning&ttsVoice=Ara&modelMode=realtime)**: Create a new agent in your browser using xai/grok-4-1-fast-non-reasoning

## Overview

The [Grok Voice Agent API](https://docs.x.ai/docs/guides/voice) enables low-latency, two-way voice interactions using Grok models. LiveKit's xAI plugin includes a `RealtimeModel` class that allows you to create agents with natural, human-like voice conversations.

Grok Voice Agent API is compatible with OpenAI's Realtime API.

### Installation

Install the xAI plugin:

**Python**:

```shell
uv add "livekit-agents[xai]~=1.5"

```

---

**Node.js**:

```shell
pnpm add "@livekit/agents-plugin-xai@1.x"

```

### Authentication

The xAI plugin requires an [xAI API key](https://console.x.ai/).

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](https://docs.livekit.io/agents/start/voice-ai.md).

**Python**:

```python
from livekit.agents import AgentSession
from livekit.plugins import xai

session = AgentSession(
    llm=xai.realtime.RealtimeModel(voice="Ara"),
)

```

---

**Node.js**:

```typescript
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](#additional-resources) section.

- **`model`** _(str)_ (optional) - Default: `'grok-voice-think-fast-1.0'`: Model ID for the Grok Voice Agent API. For the full list, see [the xAI documentation](https://docs.x.ai/developers/model-capabilities/audio/voice-agent#model-selection).

- **`voice`** _(str)_ (optional) - Default: `'ara'`: Voice to use for speech generation. For a list of available voices, see [Available voices](https://docs.x.ai/docs/guides/voice/agent#available-voices).

- **`api_key`** _(str)_ - Environment: `XAI_API_KEY`: xAI API key.

- **`turn_detection`** _(TurnDetection | None)_ (optional): 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.

xAI 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](https://docs.x.ai/docs/key-information/collections)) on xAI

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

```python
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:

**Python**:

```python
from livekit.agents import AgentSession
from livekit.plugins import xai
from openai.types.beta.realtime.session import TurnDetection

session = AgentSession(
    llm=xai.RealtimeModel(
        turn_detection=TurnDetection(
            type="server_vad",
            threshold=0.5,
            prefix_padding_ms=300,
            silence_duration_ms=200,
            create_response=True,
            interrupt_response=True,
        )
    ),
)

```

---

**Node.js**:

```typescript
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 xAI with LiveKit Agents.

- **[Grok Voice Agent API docs](https://docs.x.ai/docs/guides/voice)**: Grok Voice Agent API documentation.

- **[Voice AI quickstart](https://docs.livekit.io/agents/start/voice-ai.md)**: Get started with LiveKit Agents and xAI.

- **[xAI LLM plugin](https://docs.livekit.io/agents/models/llm/xai.md)**: Use xAI Grok as an LLM provider for your agents.

---

This document was rendered at 2026-06-07T11:35:39.477Z.
For the latest version of this document, see [https://docs.livekit.io/agents/models/realtime/plugins/xai.md](https://docs.livekit.io/agents/models/realtime/plugins/xai.md).

To explore all LiveKit documentation, see [llms.txt](https://docs.livekit.io/llms.txt).