# xAI Grok (/en/ai/models/mllm/xai)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

> Documentation: Conversational AI.
> Documentation version: Main.
> This document describes only this version. [Version index](/llms/doc-versions-convoai-guides-v1.txt).


xAI Grok provides multimodal large language model capabilities with real-time audio processing, enabling natural voice conversations without separate ASR/TTS components. This page covers integration using the xAI Realtime API, authenticated with an API key obtained from the xAI developer console. Enabling MLLM automatically disables ASR, LLM, and TTS since the MLLM handles end-to-end voice processing directly.

### Sample configuration

The following examples show how to configure xAI Grok MLLM when starting a conversational AI agent.

**Python SDK**

```python
from agora_agent import Agent
from agora_agent.agentkit.vendors import XaiGrok

# client is your configured Agora client
agent = (
    Agent(client)
    .with_mllm(XaiGrok(
        api_key='your-xai-key',
        voice='eve',
        language='en',
        sample_rate=24000,
    ))
)
```

**TypeScript SDK**

```typescript
import { Agent, XaiGrok } from 'agora-agents';

// client is your configured Agora client
const agent = new Agent({ client })
  .withMllm(new XaiGrok({
    apiKey: 'your-xai-key',
    voice: 'eve',
    language: 'en',
    sampleRate: 24000,
  }));
```

**Go SDK**

```go
import (
    Agora "github.com/AgoraIO/agora-agents-go/v2"
    "github.com/AgoraIO/agora-agents-go/v2/agentkit"
    "github.com/AgoraIO/agora-agents-go/v2/agentkit/vendors"
)

// client is your configured Agora client
agent := agentkit.NewAgent(client).WithMllm(
    vendors.NewXaiGrok(vendors.XaiGrokOptions{
        APIKey:     "your-xai-key",
        Voice:      "eve",
        Language:   "en",
        SampleRate: Agora.Int(24000),
    }),
)
```

**REST API**

Use the following `mllm` configuration in your request:

```json
"mllm": {
  "enable": true,
  "vendor": "xai",
  "url": "wss://api.x.ai/v1/realtime",
  "api_key": "<XAI_API_KEY>",
  "messages": [
    {
      "role": "user",
      "content": "<HISTORY_CONTENT>"
    }
  ],
  "output_modalities": [
    "audio",
    "text"
  ],
  "params": {
    "voice": "eve",
    "language": "en",
    "sample_rate": 24000
  },
  "turn_detection": {
    // see details below
  },
  "greeting_message": "Hello, how can I help?"
}
```

### Turn detection

To set up turn detection, add a `turn_detection` block inside the `mllm` object when you [Start a conversational AI agent](/en/api-reference/api-ref/conversational-ai/join).

> **Info**
>
> When `mllm.turn_detection` is defined, the top-level `turn_detection` object has no effect.

The following examples show the supported configurations for xAI Grok.

- **Server VAD**

  ```json
  "turn_detection": {
    "mode": "server_vad",
    "server_vad_config": {
      "threshold": 0.5,
      "prefix_padding_ms": 640,
      "silence_duration_ms": 900
    }
  }
  ```


- **Agora VAD**

  ```json
  "turn_detection": {
    "mode": "agora_vad",
    "agora_vad_config": {
      "threshold": 0.5,
      "interrupt_duration_ms": 160,
      "prefix_padding_ms": 800,
      "silence_duration_ms": 640
    }
  }
  ```

### Key parameters

**mllm required**

**`enable` (boolean) optional**

Enables the MLLM module. Replaces the deprecated `advanced_features.enable_mllm`.

**`vendor` (string) required**

The MLLM provider identifier. Set to `"xai"` to use xAI Grok.

**`url` (string) required**

The WebSocket endpoint for the xAI Realtime API. Set to `"wss://api.x.ai/v1/realtime"`.

**`api_key` (string) required**

The xAI API key used to authenticate requests. Get your API key from the [xAI Console](https://console.x.ai/home).

**`messages` (array[object]) optional**

An array of conversation history items passed to the model as context. Each item represents a single message in the conversation history.

**`role` (string) required**

The role of the message author. For example, `system` or `user`.

**`content` (string) required**

The content of the message.

**`params` (object) required**

Configuration object for the xAI Grok model.

**`voice` (string) optional**

The voice identifier for audio output. For example, `eve` or `rex`.

**`language` (string) optional**

The language code for speech recognition and synthesis. For example, `en`.

**`sample_rate` (integer) optional**

The audio sample rate in Hz. For example, `24000`.

**`turn_detection` (object) optional**

Turn detection configuration for the MLLM module. For a full list of `turn_detection` parameters, see [`mllm.turn_detection`](/en/api-reference/api-ref/conversational-ai/join#request-body-properties-mllm-turn-detection).

**`mode` (string) optional**

Possible values: `agora_vad, server_vad`

- `agora_vad`: Agora VAD-based detection.
- `server_vad`: Vendor-side VAD-based detection.

**`agora_vad_config` (object) optional**

Configuration for Agora VAD-based turn detection. Applicable when `mode` is `agora_vad`.

**`interrupt_duration_ms` (integer) optional**

Minimum duration of speech in milliseconds required to trigger an interruption.

**`prefix_padding_ms` (integer) optional**

Duration of audio in milliseconds to include before the detected speech start.

**`silence_duration_ms` (integer) optional**

Duration of silence in milliseconds required to determine end of speech.

**`threshold` (number) optional**

VAD sensitivity threshold. A higher value reduces false positives.

**`server_vad_config` (object) optional**

Configuration for vendor-side VAD-based turn detection. Applicable when `mode` is `server_vad`. Parameters are passed through to the vendor.

**`threshold` (number) optional**

VAD sensitivity threshold. A higher value reduces false positives.

**`prefix_padding_ms` (integer) optional**

Duration of audio in milliseconds to include before the detected speech start.

**`silence_duration_ms` (integer) optional**

Duration of silence in milliseconds required to determine end of speech.

**`output_modalities` (array[string]) optional**

Default value: `["audio"]`

Output modalities for the MLLM.

- `["audio"]`: Audio-only output
- `["text", "audio"]`: Combined text and audio output

**`greeting_message` (string) optional**

The message the agent speaks when a user joins the channel.

**`failure_message` (string) optional**

The message the agent speaks when an error occurs.

For comprehensive API reference, real-time capabilities, and detailed parameter descriptions, see the [xAI Voice Agent API](https://docs.x.ai/developers/model-capabilities/audio/voice-agent).
