Overview
GrokLLMService provides access to Grok’s language models through an OpenAI-compatible interface. It inherits from OpenAILLMService and supports streaming responses, function calling, and context management with Grok’s unique reasoning capabilities.
Grok LLM API Reference
Pipecat’s API methods for Grok integration
Example Implementation
Complete example with function calling
Grok Documentation
Official Grok API documentation and features
X.AI Platform
Access Grok models and manage API keys
Installation
To use Grok services, install the required dependencies:Prerequisites
Grok Account Setup
Before using Grok LLM services, you need:- X.AI Account: Sign up at X.AI Console
- API Key: Generate an API key from your console dashboard
- Model Selection: Choose from available Grok models
Required Environment Variables
XAI_API_KEY: Your X.AI API key for authentication
Configuration
str
required
X.AI API key for authentication. Raises
ValueError when empty.str
default:"https://api.x.ai/v1"
Base URL for Grok API endpoint.
str
default:"None"
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use
settings=GrokLLMService.Settings(model=...) instead.Settings
Runtime-configurable settings passed via thesettings constructor argument using GrokLLMService.Settings(...). These can be updated mid-conversation with LLMUpdateSettingsFrame. See Service Settings for details.
Literal['none', 'low', 'medium', 'high', 'xhigh'] | None
default:"None"
How much the model thinks before answering. Accepted values vary by model:
"low", "medium", and "high" on the Grok 4 reasoning models, "xhigh" on
grok-4.6 and later, and "none" on models that can turn reasoning off. The
non-reasoning models, including the default model, reject the parameter. When
unset, xAI’s per-model default applies.OpenAILLMService. See OpenAI LLM Settings for additional parameters. The service defaults to model="grok-4.20-non-reasoning" when no model is specified.
Usage
Basic Setup
With Custom Settings
Notes
- Token usage is reported once per completion at the end of each request.
- Grok supports prompt caching and reasoning tokens, which are tracked in usage metrics when available.