Grok Build 配置

使用 Modelflare API 密钥、grok-4.5 和 Responses API 端点连接官方 Grok Build CLI。

第一步:创建 API Key

在 Modelflare 创建一个可以访问 grok-4.5 的 API Key。

第二步:安装 Grok Build

Windows PowerShell

irm https://x.ai/cli/install.ps1 | iex
grok version

Linux 或 macOS

curl -fsSL https://x.ai/cli/install.sh | bash
grok version

第三步:创建 config.toml

Windows PowerShell

New-Item -ItemType Directory -Force "$HOME\.grok" | Out-Null
Set-Location "$HOME\.grok"
$config = @'
[models]
default = "modelflare-grok"

[model.modelflare-grok]
model = "grok-4.5"
base_url = "https://modelflare.dev/v1"
name = "Modelflare Grok 4.5"
env_key = "MODELFLARE_API_KEY"
api_backend = "responses"
'@
$utf8NoBom = New-Object System.Text.UTF8Encoding -ArgumentList $false
[System.IO.File]::WriteAllText(
  (Join-Path (Get-Location) "config.toml"),
  $config,
  $utf8NoBom
)

Linux 或 macOS

mkdir -p ~/.grok
cd ~/.grok
cat > config.toml << 'EOF'
[models]
default = "modelflare-grok"

[model.modelflare-grok]
model = "grok-4.5"
base_url = "https://modelflare.dev/v1"
name = "Modelflare Grok 4.5"
env_key = "MODELFLARE_API_KEY"
api_backend = "responses"
EOF
chmod 600 config.toml

第四步:保存 API Key

执行命令前,必须把 YOUR_MODELFLARE_API_KEY 替换成你自己的完整 Modelflare API Key。

Windows PowerShell

[Environment]::SetEnvironmentVariable(
  "MODELFLARE_API_KEY",
  "YOUR_MODELFLARE_API_KEY",
  "User"
)
$env:MODELFLARE_API_KEY = "YOUR_MODELFLARE_API_KEY"

Linux

echo 'export MODELFLARE_API_KEY="YOUR_MODELFLARE_API_KEY"' >> ~/.bashrc
source ~/.bashrc

macOS

echo 'export MODELFLARE_API_KEY="YOUR_MODELFLARE_API_KEY"' >> ~/.zshrc
source ~/.zshrc

第五步:启动并测试

Windows PowerShell

Set-Location $HOME
grok -p "请只回复:Modelflare connected" -m modelflare-grok
grok

Linux 或 macOS

cd ~
grok -p "请只回复:Modelflare connected" -m modelflare-grok
grok