OpenCode: OpenCode API设置与DeepSeek
最后更新:2026-08-31
OpenCode 本身不提供 AI 模型,需要配置 API Key 接入大语言模型服务。
1. 你将学到
- OpenCode Zen 免费模式
- API Key 配置流程
- DeepSeek 接入方法
- 国内 API 配置
- CC Switch 管理工具
2. OpenCode Zen(推荐新手)
OpenCode Zen 是官方精选的一组模型,已经过测试和优化,开箱即用。Zen 中包含大量免费大模型,基本上可以直接用,不用充钱。
(1) 配置步骤
在终端输入:
opencode
在 OpenCode TUI 中输入:
/connect
选择 opencode,然后按提示获取 API Key。
(2) 获取 API Key
打开 https://opencode.ai/auth ,登录账号并创建 API Key。
(3) 粘贴 API Key
回到终端,将获取到的 API Key 粘贴进去即可。
(4) 查看可用模型
/model
标记 Free 的模型可以免费使用。
3. 接入 DeepSeek
DeepSeek 是国产高性价比大模型,推荐国内用户使用。
(1) 获取 API Key
访问 https://platform.deepseek.com/api_keys ,注册并创建 API Key。
DeepSeek 官方模型:
| 模型名称 | 说明 |
|---|---|
| deepseek-v4-flash | 快速版 |
| deepseek-v4-pro | 专业版 |
(2) 在 OpenCode 中配置
在 TUI 中输入 /connect,选择 DeepSeek,粘贴 API Key。
(3) 选择模型
/model
选择 DeepSeek 对应的模型即可。
4. 接入阿里百炼
(1) 获取 API Key
访问阿里云百炼控制台 https://bailian.console.aliyun.com/ ,登录后点击齿轮图标 → API Key → 复制或创建。
(2) 在 OpenCode 中配置
/connect
在搜索框中输入 alibaba,选中 Alibaba (China),粘贴 API Key。
(3) 选择模型
/model
选择阿里支持的模型。
5. 国内 API 一览
| 厂商 | 模型 | API 申请入口 |
|---|---|---|
| DeepSeek | deepseek-v4-flash / v4-pro | https://platform.deepseek.com/api_keys |
| 火山方舟 Coding Plan | Doubao / MiniMax / Kimi / GLM / DeepSeek | https://www.volcengine.com/activity/codingplan |
| 阿里百炼 | 千问 / GLM / Kimi / MiniMax | https://bailian.console.aliyun.com |
| GLM(智谱清言) | GLM-4 系列 | https://open.bigmodel.cn |
| MiniMax | 多模态模型 | https://platform.minimaxi.com |
进入对应控制台后,注册/登录 → 完成实名认证 → 创建 API Key 即可开始调用。
6. CC Switch 管理工具
CC Switch 是 Claude Code / Codex / OpenCode 的 API 配置管理工具,可轻松管理多个提供商的配置。
- GitHub:https://github.com/farion1231/cc-switch/
- 支持 Windows / macOS / Linux
配置步骤:
- 打开 CC Switch,选择 OpenCode 图标
- 点击右上角添加按钮
- 选择提供商(如 DeepSeek)
- 输入 API Key
- 设置模型名称
配置完成后,可在终端测试:
opencode run 解释一下 JavaScript 中闭包的原理
❓ 常见问题
~/.local/share/opencode/auth.json 中,不会上传到云端。但仍建议定期轮换 API Key。📖 小节
- 新手推荐 OpenCode Zen,含免费模型,开箱即用
- DeepSeek 是国内用户的高性价比选择
- 阿里百炼支持多种模型,适合需要灵活切换的场景
- CC Switch 可以统一管理多个 API 配置
- API Key 存储在本地,注意安全保管
📝 作业
-
基础题:配置 OpenCode Zen 或 DeepSeek API Key,成功启动 OpenCode。
-
进阶题:同时配置两个不同的 API 提供商,并在它们之间切换使用。
-
挑战题:使用 CC Switch 管理工具配置你的 API,并在命令行中完成一次非交互式调用。