入门指南
Grok Build
Grok Build 是一个功能强大且可扩展的编码代理。您可以通过交互式 TUI、在脚本或机器人中无头运行,或在其他应用中通过代理客户端协议 (ACP) 来使用它。
TUI 提供了丰富的、支持鼠标交互的全屏体验,让您能够通过代理进行编码。
安装
bash
curl -fsSL https://x.ai/cli/install.sh | bashbash
irm https://x.ai/cli/install.ps1 | iex启动交互式会话
bash
cd your-project
grok首次启动时,Grok 会打开浏览器进行身份验证。在非浏览器环境中,请使用 API 密钥:
bash
export XAI_API_KEY="xai-..."
grok有用的初始提示:
text
Explain this repo.
@src/main.rs Walk me through this file.无头运行
bash
grok -p "Explain this codebase"
grok -p "Explain the architecture" --output-format streaming-json无头模式非常适合脚本、自动化或集成到其他应用中。
自定义模型
Grok 支持任何自定义模型。将其添加到您的用户级配置文件 ~/.grok/config.toml(在 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"更新 ~/.grok/config.toml 后,使用 grok inspect 查看 Grok 在当前目录中发现的内容,包括配置源、指令、技能、插件、钩子和 MCP 服务器,然后在无头模式或 TUI 中选择模型:
bash
grok inspect
grok -p "Hello" -m my-model您也可以在 TUI 中使用 /model <name> 切换模型。
在 API 上使用 Grok 4.5
为 Grok Build 提供动力的相同模型 grok-4.5 也可以直接在 xAI API 上使用。将其集成到您自己的代理循环、IDE 集成或编码工具中。
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);