AI 编程 / OpenCode

OpenCode 接入 NewBee

创建 OpenAI Compatible Provider,统一填写 NewBee Base URL、API Key 和模型 ID。

Base URL

https://api.newbeeapi.com/v1

配置文件

~/.config/opencode/opencode.json 中创建或编辑 OpenAI provider。Windows 可使用用户目录下对应的 .config/opencode 路径。

opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "newbee": {
      "npm": "@ai-sdk/openai",
      "name": "NewBee API",
      "options": {
        "baseURL": "https://api.newbeeapi.com/v1",
        "apiKey": "sk-your-newbee-api-key"
      },
      "models": {
        "YOUR_MODEL_ID": {
          "name": "YOUR_MODEL_ID"
        }
      }
    }
  }
}

不要把真实 Key 提交到公开仓库。模型对象中的 ID 必须替换为 NewBee 模型广场当前实际 ID。

基本使用

  1. 保存配置并重新打开终端。
  2. 启动 opencode
  3. 输入 /models,选择 NewBee 模型。
  4. 发送一个低风险测试请求。

常见排查

看不到模型时检查 JSON 格式、Provider ID 和 Base URL;连接失败时检查 API Key 是否完整、模型 ID 是否有权限。OpenCode 的 Anthropic provider 不要擅自复用 OpenAI /v1 地址。