Appearance
OpenCode 集成
GPT 模型请使用 Responses API
OpenCode 通过 @ai-sdk/openai 接入 GPT 模型时,底层使用 Responses API(POST /v1/responses),即 OpenAI 推荐的新协议。
配置时注意两点:
provider必须写openai(不能写其他名字)- 必须设置
"setCachekey": true,否则缓存失效、额度浪费
@ai-sdk/openai 会自动与兼容该协议的中转端点通信,无需手动切换端点。
1. 找到配置文件
- macOS / Linux:
~/.config/opencode/opencode.json - Windows:
C:\Users\你的用户名\.config\opencode\opencode.json
2. 添加 CodexZH provider
在 opencode.json 的 provider 中添加(或合并)以下内容,将 apiKey 替换为真实的 sk- 密钥:
json
{
"provider": {
"openai": {
"npm": "@ai-sdk/openai",
"name": "codexzh",
"options": {
"baseURL": "https://api.codexzh.com/v1",
"apiKey": "sk-替换成你自己的 key",
"setCachekey": true,
"options": {
"reasoningEffort": "high",
"textVerbosity": "low",
"reasoningSummary": "auto"
}
},
"models": {
"gpt-5.4": { "name": "gpt-5.4" },
"gpt-5.3-codex": { "name": "gpt-5.3-codex" }
}
}
}
}3. 重启 OpenCode
配置完成后重启 OpenCode 才能生效。
4. 选择模型
在 OpenCode 中选择 codexzh 作为提供者,然后选择 gpt-5.4 模型。
5. 常见问题
- 配置不生效:检查
opencode.json是否为合法 JSON(注意逗号、引号、括号) - 鉴权失败:确认
apiKey复制完整,且账号已激活