OpenCode

最近更新时间:2026-05-18 19:41:21

我的收藏
OpenCode 是一款开源的 AI 编程代理工具,提供终端界面、桌面应用和 IDE 扩展等多种使用方式。本文介绍如何在 OpenCode 中配置与使用腾讯云大模型 Token Plan。

前置条件

在开始配置前,请确保您已完成以下准备工作:
3. 安装 OpenCode:
3.1. 执行如下命令安装 OpenCode,更多操作可参考 OpenCode 官方配置指引
npm install -g opencode-ai
3.2. 安装完成后,您可以执行如下命令检查,输出版本号则表示安装成功。
opencode -v

配置模型

1. 您需要按照下面的示例修改 OpenCode 的配置文件,配置文件路径如下,配置文件不存在时新建即可。
macOS / Linux:~/.config/opencode/opencode.json
Windows:C:\\Users\\<用户名>\\.config\\opencode\\opencode.json
说明:
请您将 $your_api_key 替换为 Token Plan 专属的 API Key。
2. 根据您购买的套餐类型,复制粘贴如下配置到 opencode.json 文件中,并保存。
配置通用 Token Plan
配置 Hy Token Plan
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"myprovider": {
"npm": "@ai-sdk/openai-compatible",
"name": "通用 Token Plan",
"options": {
"baseURL": "https://api.lkeap.cloud.tencent.com/plan/v3",
"apiKey": "$your_api_key"
},
"models": {
"tc-code-latest": {
"name": "Auto",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
},
"minimax-m2.5": {
"name": "MiniMax-M2.5",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
},
"minimax-m2.7": {
"name": "MiniMax-M2.7",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
},
"glm-5": {
"name": "GLM-5",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
},
"glm-5.1": {
"name": "GLM-5.1",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
},
"kimi-k2.5": {
"name": "Kimi-K2.5",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
}
}
}
}
}
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"myprovider": {
"npm": "@ai-sdk/openai-compatible",
"name": "Hy Token Plan",
"options": {
"baseURL": "https://api.lkeap.cloud.tencent.com/plan/v3",
"apiKey": "$your_api_key"
},
"models": {
"hy3-preview": {
"name": "Hy3-preview",
"modalities": {
"input": [
"text"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled"
}
}
}
}
}
}
}

使用 OpenCode

1. 执行如下命令启动 OpenCode:
opencode
2. 输入/models

3. 选择配置的模型并在 OpenCode 中使用,以下以选择通用 Token Plan 的 Auto 模型为例:

4. 完成上述配置后,即可开始使用 OpenCode。