OpenCode
OpenCode 是带终端 UI 与桌面应用的开源 AI 编程 Agent,支持多会话、LSP 集成等能力。ApiGo 不是内置 provider——请用 @ai-sdk/openai-compatible 注册自定义 provider,一把 Key 即可切换多厂商模型。
安装
curl -fsSL https://opencode.ai/install | bash
其他方式:
npm install -g opencode-ai
brew install anomalyco/tap/opencode
更多安装方式(Bun、pnpm、Yarn、Arch、Windows)见 OpenCode 文档。
配置 ApiGo
在项目中创建或编辑 opencode.json(也可放在 OpenCode 的全局配置位置):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"apigo": {
"npm": "@ai-sdk/openai-compatible",
"name": "ApiGo",
"options": {
"baseURL": "https://api.apigo.ai/v1"
},
"models": {
"gpt-5.6-sol": {
"name": "GPT-5.6 Sol"
},
"qwen3.8-max": {
"name": "Qwen 3.8 Max"
},
"deepseek-v4-flash": {
"name": "DeepSeek V4 Flash"
}
}
}
}
}
把 models 下的 key 换成 模型目录 中的真实 slug。apigo 是自定义 provider ID,可按需改名,但需与 auth 文件中的键保持一致。
添加 API Key
方式 A:TUI 中 /connect(推荐)
cd /path/to/your/project
opencode
- 运行
/connect - 选择你定义的 ApiGo provider
- 粘贴
sk-apigo-...
方式 B:auth 文件
写入 ~/.local/share/opencode/auth.json(路径可能因系统 / 安装方式而异):
{
"apigo": {
"type": "api",
"key": "sk-apigo-..."
}
}
不要把含真实 Key 的文件提交到版本库。
选择模型并验证
在 OpenCode 内:
/models
选中 ApiGo 下的模型后开始编码。验证清单:
- 发一句短提示,确认有正常回复
- 打开 Call Logs 确认请求到达
- 如需切换模型,再次使用
/models,无需改 Key
可选:Anthropic Base URL 覆盖
若只想让内置 Anthropic provider 走 ApiGo 的 Claude 原生协议:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"options": {
"baseURL": "https://api.apigo.ai"
}
}
}
}
对该 provider 使用你的 ApiGo Key。若希望多厂商共用一把 Key,优先使用上方自定义 apigo provider。
故障排除
| 现象 | 处理 |
|---|---|
| 鉴权错误 | 重新 /connect,或检查 auth.json 中的 provider 键名是否与 opencode.json 一致 |
| 模型未出现 | 在 provider.apigo.models 中加入精确 slug 后重启 OpenCode |
| 请求未到 ApiGo | 确认 options.baseURL 为 https://api.apigo.ai/v1 |
| npm 包拉取失败 | 确认本机可访问 npm,并安装 @ai-sdk/openai-compatible 所需依赖 |
