Overview
This plugin allows you to use xAI as an LLM provider for your voice agents. The xAI plugin supports the Responses API, which provides support for xAI's provider tools (WebSearch, FileSearch, XSearch) and is the recommended endpoint.
Installation
Install the xAI plugin to add xAI support:
uv add "livekit-agents[xai]~=1.4"
Authentication
Set the following environment variable in your .env file:
XAI_API_KEY=<your-xai-api-key>
Usage
Use xAI within an AgentSession or as a standalone LLM service. For example, you can use this LLM in the Voice AI quickstart
from livekit.plugins import xai# Use Responses API (recommended)session = AgentSession(llm=xai.responses.LLM(model="grok-4-1-fast-non-reasoning",),# ... tts, stt, vad, turn_handling, etc.)
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.
strOptionalDefault: grok-4-1-fast-non-reasoningGrok model to use. To learn more, see the xAI Grok models page.
floatOptionalDefault: 1.0Controls the randomness of the model's output. Higher values, for example 0.8, make the output more random, while lower values, for example 0.2, make it more focused and deterministic.
Valid values are between 0 and 2. To learn more, see the optional parameters for Responses
boolOptionalControls whether the model can make multiple tool calls in parallel. When enabled, the model can make multiple tool calls simultaneously, which can improve performance for complex tasks.
ToolChoice | Literal['auto', 'required', 'none']OptionalDefault: autoControls how the model uses tools. Set to 'auto' to let the model decide, 'required' to force tool usage, or 'none' to disable tool usage.
Provider tools
xAI supports the following 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. Provider tools work with both the Responses API and the Grok Voice Agent API.
| Tool | Description | Parameters |
|---|---|---|
XSearch | Search X (Twitter) posts. | allowed_x_handles |
WebSearch | Search the web and browse pages. | None |
FileSearch | Search uploaded document collections. | vector_store_ids (required), max_num_results |
from livekit.plugins import xaiagent = MyAgent(llm=xai.responses.LLM(),tools=[xai.XSearch(), xai.WebSearch()], # replace with any supported provider tool)
Additional resources
The following links provide more information about the xAI Grok LLM integration.