---
title: "xAI Grok"
description: "Access xAI's Grok models with real-time knowledge and advanced reasoning capabilities. Built for developers who want cutting-edge AI assistance."
sidebar:
  label: "XAI Grok"
seo:
  title: "xAI Grok Integration"
  description: "Connect to xAI's Grok models for real-time knowledge and advanced reasoning. Complete setup guide for xAI API integration."
---

## What is the Autohand xAI Grok integration? [#quick-answer]

The Autohand xAI integration connects the coding agent to Grok models through the xAI API. It uses an xAI API key and a model identifier that is available to the configured account.

|  |  |
| --- | --- |
| Status | Available |
| Requires | An xAI API key, account billing, and access to the selected Grok model. |
| Configure with | Put your key in `xai.apiKey` in `~/.autohand/config.json` (the CLI does not read `XAI_API_KEY`), select the `xai` provider, and choose a model ID currently available to the xAI account. |
| Best for | Direct use of Grok models from Autohand. |

:::warning
**Know before you start:** Model identifiers, feature support, context limits, quotas, and prices are controlled by xAI and may change.
:::

## Overview

xAI's Grok models offer unique capabilities for code assistance. When integrated with Autohand, you get:

- Access to Grok-2 and Grok-2 mini models
- Real-time knowledge from X (Twitter) data
- Large 128K context window
- Vision capabilities for image understanding
- Function calling support

:::tip
**API access:** xAI API is available through [console.x.ai](https://console.x.ai). You'll need an xAI account with API access enabled.
:::

## Setup

Get started with xAI Grok.

### Get your API key

1. Go to [console.x.ai](https://console.x.ai) and sign in
2. Navigate to **API Keys**
3. Create a new API key and copy it

### Configure Autohand

```bash
# Save the key in ~/.autohand/config.json
autohand config set xai.apiKey "xai-xxxxxxxxxxxxxxxxxxxx"
```

Verify your configuration:

```bash
# Start with xAI provider
autohand --provider xai --model grok-2

# Test with a prompt
autohand --prompt "Hello, which model are you?"
```

## CLI configuration

Configure xAI in your `~/.autohand/config.json`:

```json
{
  "provider": "xai",
  "xai": {
    "apiKey": "xai-xxxxxxxxxxxxxxxxxxxx",
    "model": "grok-2"
  }
}
```

### Configuration options

| Option | Description | Default |
| --- | --- | --- |
| `apiKey` | Your xAI API key | \- |
| `model` | Model to use | `grok-2` |
| `baseUrl` | API endpoint | `https://api.x.ai/v1` |

## Available models [#models]

xAI offers Grok models optimized for different use cases.

| Model | Context | Best for |
| --- | --- | --- |
| `grok-2` | 128K | Most capable, complex tasks |
| `grok-2-mini` | 128K | Fast and cost-effective |
| `grok-2-vision` | 128K | Image understanding |

### Switch models

```bash
# Set default model
autohand config set xai.model "grok-2"

# Use a model for one run
autohand --model "grok-2-mini"

# During a session, open the model picker
/model
```

## Best practices

- **Use environment variables**: Keep API keys out of version control.
- **Choose the right model**: Use grok-2 for complex tasks, grok-2-mini for quick responses.
- **Monitor usage**: Check your xAI console for usage metrics.

## Resources

- [xAI Website](https://x.ai)
- [API Documentation](https://docs.x.ai)
- [Developer Console](https://console.x.ai)
- [Available Models](https://docs.x.ai/docs/models)
- [API Pricing](https://x.ai/api)

## Troubleshooting

### Common issues

| Issue | Solution |
| --- | --- |
| Invalid API key | Verify key at [console.x.ai](https://console.x.ai) |
| Rate limited | Wait or check your rate limits |
| Model not available | Check model access in your account |

### Debug mode

```bash
# Enable verbose logging
AUTOHAND_DEBUG=true autohand --provider xai
```

**How do I configure the Autohand xAI Grok integration?**

Put your key in `xai.apiKey` in `~/.autohand/config.json` (the CLI does not read `XAI_API_KEY`), select the `xai` provider, and choose a model ID currently available to the xAI account.

**What does the Autohand xAI Grok integration require?**

An xAI API key, account billing, and access to the selected Grok model.

**What limitations should I know about?**

Model identifiers, feature support, context limits, quotas, and prices are controlled by xAI and may change.
