Skip to content

Getting Started

Grok Build

Grok Build is a powerful and extensible coding agent. Use it via an interactive TUI, headlessly in scripts or bots, or through the Agent Client Protocol (ACP) in other apps.

The TUI provides a rich, mouse-interactive, fullscreen experience for coding with agents.

Install

bash
curl -fsSL https://x.ai/cli/install.sh | bash
bash
irm https://x.ai/cli/install.ps1 | iex

Start an interactive session

bash
cd your-project
grok

On first launch, Grok opens a browser for authentication. In non-browser environments, use an API key:

bash
export XAI_API_KEY="xai-..."
grok

Useful first prompts:

text
Explain this repo.
@src/main.rs Walk me through this file.

Run headlessly

bash
grok -p "Explain this codebase"
grok -p "Explain the architecture" --output-format streaming-json

Headless usage is ideal for scripts, automations, or integration into other apps.

Custom models

Grok supports any custom model. Add it to your user-level config file, ~/.grok/config.toml (on Windows, %USERPROFILE%\.grok\config.toml):

text
[model.my-model]
model = "model-id"
base_url = "https://api.example.com/v1"
name = "Display Name"
env_key = "API_KEY"

[models]
default = "my-model"

After updating ~/.grok/config.toml, use grok inspect to see what Grok discovered in the current directory, including config sources, instructions, skills, plugins, hooks, and MCP servers, then pick the model in headless mode or in the TUI:

bash
grok inspect
grok -p "Hello" -m my-model

You can also switch inside the TUI with /model <name>.

Use Grok 4.5 on the API

The same model that powers Grok Build, grok-4.5, is also available directly on the xAI API. Drop it into your own agent loop, IDE integration, or coding tool.

bash
curl https://api.x.ai/v1/responses \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.5",
    "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"
  }'
python
import os
from xai_sdk import Client
from xai_sdk.chat import user

client = Client(api_key=os.getenv("XAI_API_KEY"))

chat = client.chat.create(model="grok-4.5")
chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"))

print(chat.sample().content)
python
from openai import OpenAI

client = OpenAI(
    api_key="<YOUR_XAI_API_KEY_HERE>",
    base_url="https://api.x.ai/v1",
)

response = client.responses.create(
    model="grok-4.5",
    input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",
)

print(response.output_text)
javascript
import { xai } from '@ai-sdk/xai';
import { generateText } from 'ai';

const { text } = await generateText({
  model: xai.responses('grok-4.5'),
  prompt: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',
});

console.log(text);

Next

💬