OpenCode 配置|ApiPorter
将 OpenCode 作为 OpenAI 兼容提供商连接到 ApiPorter,并在支持的模型之间切换。
第一步:创建 API Key
在 ApiPorter 创建一个可以访问 gpt-5.6-sol 的非 default 分组 API Key。
第二步:安装 OpenCode
Windows PowerShell
choco install opencode
opencode --versionLinux 或 macOS
curl -fsSL https://opencode.ai/install | bash
opencode --version如果安装失败,请改用下面的命令:
npm install -g opencode-ai@latest --registry=https://registry.npmmirror.com第三步:创建 opencode.json
进入你的项目目录,然后执行当前系统对应的命令。
Windows PowerShell
$config = @'
{
"$schema": "https://opencode.ai/config.json",
"model": "apiporter/gpt-5.6-sol",
"provider": {
"apiporter": {
"npm": "@ai-sdk/openai-compatible",
"name": "ApiPorter",
"options": { "baseURL": "https://www.apiporter.com/v1" },
"models": {
"gpt-5.6-sol": { "name": "GPT 5.6 Sol" }
}
}
}
}
'@
$utf8NoBom = New-Object System.Text.UTF8Encoding -ArgumentList $false
[System.IO.File]::WriteAllText(
(Join-Path (Get-Location) "opencode.json"),
$config,
$utf8NoBom
)Linux 或 macOS
cat > opencode.json << 'EOF'
{
"$schema": "https://opencode.ai/config.json",
"model": "apiporter/gpt-5.6-sol",
"provider": {
"apiporter": {
"npm": "@ai-sdk/openai-compatible",
"name": "ApiPorter",
"options": { "baseURL": "https://www.apiporter.com/v1" },
"models": {
"gpt-5.6-sol": { "name": "GPT 5.6 Sol" }
}
}
}
}
EOF第四步:绑定 API Key
在同一个项目目录启动 OpenCode:
opencode输入 /connect,选择 Other,把 provider id 填为 apiporter,然后粘贴你的 ApiPorter API Key。
第五步:选择模型并测试
输入 /models,选择 apiporter/gpt-5.6-sol,然后发送:
请用一句话向我问好。能够正常回复,就说明配置完成。