Skip to content

OpenCode

OpenCode 是开源终端 / IDE 编程 Agent。通过 ~/.config/opencode/opencode.json 添加 Trinity 供应商(provider id trinity),用 xh-... Key 调用 模型广场 中的模型。


获取 API Key

  1. 控制台 · API 密钥 创建 Key(xh-...)。
  2. 管理 API 密钥

模型 ID 见 模型广场


快速配置

写入 ~/.config/opencode/opencode.json。按所选模型协议选择 Base URL 与 npm SDK:Anthropic Messages 不带 /v1@ai-sdk/anthropic);Responses / Chat Completions 带 /v1(分别为 @ai-sdk/openai@ai-sdk/openai-compatible)。

bash
npx -y trinity-config@latest --type opencode -k xh-你的key --model gpt-5.4

配置完成后,在 OpenCode 内用 /models 选择 trinity/<model_code>


手动配置

编辑 ~/.config/opencode/opencode.json。Provider id 为 trinity,模型引用为 trinity/<model_code>

Base URL:

协议baseURLnpm
Anthropic Messageshttps://api.trinitydesk.ai(不带 /v1@ai-sdk/anthropic
Responseshttps://api.trinitydesk.ai/v1@ai-sdk/openai
Chat Completionshttps://api.trinitydesk.ai/v1@ai-sdk/openai-compatible

Responses 示例(gpt-5.4):

json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "trinity/gpt-5.4",
  "provider": {
    "trinity": {
      "npm": "@ai-sdk/openai",
      "name": "Trinity",
      "options": {
        "baseURL": "https://api.trinitydesk.ai/v1",
        "apiKey": "xh-你的key"
      },
      "models": {
        "gpt-5.4": { "name": "gpt-5.4" }
      }
    }
  }
}

在 OpenCode 中用 /models 选择 trinity/gpt-5.4

故障排查

问题排查
401 Unauthorized确认 API Key 以 xh- 开头且未过期
403 model_not_allowed在控制台确认 Key 有该模型的调用权限
连接超时确认 Base URL 正确(Anthropic 不带 /v1,其余带 /v1
模型未找到模型广场 核对模型 ID

WARNING

不要将 API Key 提交到 Git 仓库。使用环境变量或配置文件管理 Key,定期轮换。

© Trinity AI