入门
Grok Build
Grok Build 是一个强大且可扩展的编程 Agent。你可以通过交互式 TUI 使用它,也可以在脚本或 bot 中以 headless 方式运行,或通过 Agent Client Protocol(ACP)在其他应用中使用。
TUI 提供功能丰富、支持鼠标交互的全屏 Agent 编程体验。
安装
curl -fsSL https://x.ai/cli/install.sh | bash启动交互式 session
cd your-project
grok首次启动时,Grok 会打开浏览器进行身份验证。在没有浏览器的环境中,请使用 API key:
export XAI_API_KEY="xai-..."
grok一些适合开始使用的 prompt:
Explain this repo.
@src/main.rs Walk me through this file.以 Headless 方式运行
grok -p "Explain this codebase"
grok -p "Explain the architecture" --output-format streaming-jsonHeadless 用法非常适合脚本、自动化或集成到其他应用中。
Custom models
Grok 支持任意 custom model。将其添加到用户级配置文件 ~/.grok/config.toml(Windows 上为 %USERPROFILE%\.grok\config.toml):
[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 在当前目录中发现的内容,包括配置来源、instructions、skills、plugins、hooks 和 MCP servers,然后在 headless 模式或 TUI 中选择模型:
grok inspect
grok -p "Hello" -m my-model也可以在 TUI 内使用 /model <name> 切换模型。
在 API 上使用 Grok 4.5
为 Grok Build 提供能力的同一模型 grok-4.5 也可以直接通过 xAI API 使用。将它集成到你自己的 Agent loop、IDE integration 或编程工具中。
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]}"
}'