Grok Build 配置|ApiPorter
使用 ApiPorter API Key、grok-4.5 和 Responses API 端点连接官方 Grok Build CLI。
第一步:创建 API Key
在 ApiPorter 创建一个可以访问 grok-4.5 的 API Key。
第二步:安装 Grok Build
Windows PowerShell
irm https://x.ai/cli/install.ps1 | iex
grok versionLinux 或 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 = "apiporter-grok"
[model.apiporter-grok]
model = "grok-4.5"
base_url = "https://www.apiporter.com/v1"
name = "ApiPorter Grok 4.5"
env_key = "APIPORTER_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 = "apiporter-grok"
[model.apiporter-grok]
model = "grok-4.5"
base_url = "https://www.apiporter.com/v1"
name = "ApiPorter Grok 4.5"
env_key = "APIPORTER_API_KEY"
api_backend = "responses"
EOF
chmod 600 config.toml第四步:保存 API Key
执行命令前,必须把 YOUR_APIPORTER_API_KEY 替换成自己的完整密钥。
Windows PowerShell
[Environment]::SetEnvironmentVariable(
"APIPORTER_API_KEY",
"YOUR_APIPORTER_API_KEY",
"User"
)
$env:APIPORTER_API_KEY = "YOUR_APIPORTER_API_KEY"Linux
echo 'export APIPORTER_API_KEY="YOUR_APIPORTER_API_KEY"' >> ~/.bashrc
source ~/.bashrcmacOS
echo 'export APIPORTER_API_KEY="YOUR_APIPORTER_API_KEY"' >> ~/.zshrc
source ~/.zshrc第五步:启动并测试
Windows PowerShell
Set-Location $HOME
grok -p "请只回复:ApiPorter connected" -m apiporter-grok
grokLinux 或 macOS
cd ~
grok -p "请只回复:ApiPorter connected" -m apiporter-grok
grok