> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Grok

> LLM service implementation using Grok's API with OpenAI-compatible interface

## 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.

<CardGroup cols={2}>
  <Card title="Grok LLM API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.xai.llm.html">
    Pipecat's API methods for Grok integration
  </Card>

  <Card title="Example Implementation" icon="play" href="https://github.com/pipecat-ai/pipecat/blob/main/examples/function-calling/function-calling-grok.py">
    Complete example with function calling
  </Card>

  <Card title="Grok Documentation" icon="book" href="https://docs.x.ai/docs/api-reference#chat-completions">
    Official Grok API documentation and features
  </Card>

  <Card title="X.AI Platform" icon="microphone" href="https://console.x.ai/">
    Access Grok models and manage API keys
  </Card>
</CardGroup>

## Installation

To use Grok services, install the required dependencies:

```bash theme={null}
uv add "pipecat-ai[grok]"
```

## Prerequisites

### Grok Account Setup

Before using Grok LLM services, you need:

1. **X.AI Account**: Sign up at [X.AI Console](https://console.x.ai/)
2. **API Key**: Generate an API key from your console dashboard
3. **Model Selection**: Choose from available Grok models

### Required Environment Variables

* `XAI_API_KEY`: Your X.AI API key for authentication

## Configuration

<ParamField path="api_key" type="str" required>
  X.AI API key for authentication.
</ParamField>

<ParamField path="base_url" type="str" default="https://api.x.ai/v1">
  Base URL for Grok API endpoint.
</ParamField>

<ParamField path="model" type="str" default="None" deprecated>
  Model identifier to use.

  *Deprecated in v0.0.105. Use `settings=GrokLLMService.Settings(model=...)` instead.*
</ParamField>

<ParamField path="settings" type="GrokLLMService.Settings" default="None">
  Runtime-configurable settings. See [Settings](#settings) below.
</ParamField>

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `GrokLLMService.Settings(...)`. These can be updated mid-conversation with `LLMUpdateSettingsFrame`. See [Service Settings](/pipecat/fundamentals/service-settings) for details.

This service uses the same settings as `OpenAILLMService`. See [OpenAI LLM Settings](/api-reference/server/services/llm/openai#settings) for the full parameter reference.

## Usage

### Basic Setup

```python theme={null}
import os
from pipecat.services.xai.llm import GrokLLMService

llm = GrokLLMService(
    api_key=os.getenv("XAI_API_KEY"),
    model="grok-3",
)
```

### With Custom Settings

```python theme={null}
from pipecat.services.xai.llm import GrokLLMService

llm = GrokLLMService(
    api_key=os.getenv("XAI_API_KEY"),
    settings=GrokLLMService.Settings(
        model="grok-3",
        temperature=0.7,
        top_p=0.9,
        max_completion_tokens=1024,
    ),
)
```

## Notes

* Grok uses incremental token reporting. The service accumulates token usage metrics during processing and reports the final totals at the end of each request.
* Grok supports prompt caching and reasoning tokens, which are tracked in usage metrics when available.

<Tip>
  The `InputParams` / `params=` pattern is deprecated as of v0.0.105. Use
  `Settings` / `settings=` instead. See the [Service Settings
  guide](/pipecat/fundamentals/service-settings) for migration details.
</Tip>
