在 OpenCode 中使用 OAIRoute
- 终端里的编程代理,没有图形界面
- 提供方写进 ~/.config/opencode/opencode.json
- 切换厂商只改模型名
第一步:获取 API Key
在 OAIRoute 控制台 创建。
Create one in the OAIRoute console.
第二步:写入配置文件
OpenCode 从 ~/.config/opencode/opencode.json 读取提供方。把下面的 JSON 存进去,把 Key 换成你自己的:
{
"provider": {
"oairoute": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.oairoute.com/v1",
"apiKey": "YOUR_OAIROUTE_KEY"
},
"models": {
"claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" },
"gpt-4o-mini": { "name": "GPT-4o mini" }
}
}
}
}OpenCode reads providers from ~/.config/opencode/opencode.json. Save the JSON below there and replace the key with your own:
{
"provider": {
"oairoute": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.oairoute.com/v1",
"apiKey": "YOUR_OAIROUTE_KEY"
},
"models": {
"claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" },
"gpt-4o-mini": { "name": "GPT-4o mini" }
}
}
}
}第三步:启动并验证
在终端里执行 opencode,用模型切换器选中刚配的 oairoute 提供方,再随便问一句确认能通。
Run opencode in your terminal, pick the oairoute provider with the model switcher, and send a short prompt to confirm it works.
配置项说明
| 字段 | 填什么 |
|---|---|
| npm | @ai-sdk/openai-compatible,OpenCode 用它加载兼容层 |
| options.baseURL | https://api.oairoute.com/v1 |
| options.apiKey | 你的 OAIRoute Key |
| models | 想在下拉里出现的模型 ID,键名就是模型 ID |
models 只影响下拉里显示什么,不限制实际能调用的模型。想用没列出来的模型,直接填模型 ID 也能走通。
| Field | What to enter |
|---|---|
| npm | @ai-sdk/openai-compatible, the compatibility layer OpenCode loads |
| options.baseURL | https://api.oairoute.com/v1 |
| options.apiKey | Your OAIRoute key |
| models | Model IDs you want in the picker; the key is the model ID itself |
models only controls what the picker lists, not what you can call. Model IDs you did not list still work.
常见问题
配置改了没生效
确认文件路径正确:macOS / Linux 是 ~/.config/opencode/opencode.json,Windows 跟随你的 XDG 配置目录。
流式或工具调用异常
检查 npm 字段是否写成了 @ai-sdk/openai-compatible,以及 baseURL 是否以 /v1 结尾。
返回 401
Key 没填对,或填成了 ark 站的 Key。两站 Key 不通用。
The config change has no effect
Double-check the path: ~/.config/opencode/opencode.json on macOS and Linux; Windows follows your XDG config directory.
Streaming or tool calls misbehave
Check that npm is @ai-sdk/openai-compatible and that baseURL ends in /v1.
401 responses
The key is wrong, or it is an ark-site key. Keys are not shared between the two sites.