OpenCode
更新时间 2026-10-29 16:58:44
最近更新时间: 2026-10-29 16:58:44
本文为您介绍编码套餐接入OpenCode的详细步骤。
配置 Coding Plan
请在以下路径创建并打开配置文件 opencode.json:
macOS / Linux: ~/.config/opencode/opencode.json
Windows: C:\Users\您的用户名\.config\opencode\opencode.json
将以下配置写入文件,关键配置项:
YOUR_API_KEY为你购买的编程套餐专属的API Key。
models的配置则为 来源于您当前购买实际套餐的可用模型。
官方V1接口调用代码示例(官方目前已升级至V2接口但也支持继续调用V1接口)
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"xirang": {
"npm": "@ai-sdk/openai-compatible",
"name": "xirang",
"options": {
"baseURL": "https://ai.ctaigw.cn/coding/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"DeepSeek-V4-Flash-0731": {
"name": "DeepSeek-V4-Flash-0731"
},
"GLM-5.2": {
"name": "GLM-5.2"
},
"GLM-5.1": {
"name": "GLM-5.1"
}
}
}
},
"model": "xirang/GLM-5.2",
"small_model": "xirang/DeepSeek-V4-Flash-0731"
}官方V2接口调用代码示例
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"xirang": {
"name": "xirang",
"package": "@ai-sdk/openai-compatible",
"settings": {
"baseURL": "https://ai.ctaigw.cn/coding/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"DeepSeek-V4-Flash-0731": {
"name": "DeepSeek-V4-Flash-0731"
},
"GLM-5.2": {
"name": "GLM-5.2"
},
"GLM-5.1": {
"name": "GLM-5.1"
}
}
}
},
"model": "xirang/GLM-5.2",
"small_model": "xirang/DeepSeek-V4-Flash-0731"
}运行 opencode 启动 OpenCode
在命令行中输入以下命令:
$ opencode使用 /models 命令来选择模型,例如 GLM-5-Pro。
/models