Skip to content

OpenCode

说明

订阅套餐(Token Plan / Coding Plan)专属 API Key 仅限在 AI 编程工具中使用,不可用于 API 调试、工作流平台等非交互式场景。Key 与 Base URL 请参见 快速开始 → 接入方式一览

方式一:通过 /connect 完成授权后再补充配置

  1. 安装 OpenCode。
  2. 在终端进入项目目录,执行:
bash
opencode
  1. 在 OpenCode 中输入:
text
/connect
  1. 完成 provider 凭据配置后,补充或修改 OpenCode 配置文件。

方式二:直接编辑配置文件

OpenCode 全局配置文件通常位于:

text
~/.config/opencode/opencode.json

也可以在项目根目录中创建 opencode.json 作为项目级配置。

参考配置如下:

json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://api.scnet.cn/api/llm/v1",
        "apiKey": "sk-tp-你的专属Key"
      }
    }
  },
  "model": "MiniMax-M2.5"
}

环境变量方式

也可先通过环境变量注入密钥:

Linux/macOS

bash
export OPENAI_API_KEY="sk-tp-你的专属Key"
opencode

Windows

powershell
setx OPENAI_API_KEY "sk-tp-你的专属Key"

设置后需重新打开终端窗口生效。再在配置文件中保留 baseURLmodel 配置。

使用建议

  • 建议优先使用全局配置,便于多个项目复用。
  • 若团队内多个项目需使用不同模型,可在项目级配置中覆盖 model