Skip to content

OpenCode

Configure OpenCode with the tested Nexus OpenAI-compatible provider fixture.

Updated View as Markdown
Audience: user-integratorPlane: dataAuth: inference-keyStatus: beta

Outcome

OpenCode 通过 Nexus Gateway 使用一条明确的 ProviderConnection,API Key 来自环境变量,模型 ID 保持上游原始值。

Prerequisites

安装 OpenCode,并准备应用交付的 Inference Key。配置格式使用 OpenCode 官方的 @ai-sdk/openai-compatible 自定义 Provider 能力。

Configure

将受测 Fixture 保存为项目根目录的 opencode.json。替换 Base URL 中的 UUID 和模型 ID;不要添加任意上游 Host 字段。

opencode.jsonjson
{
  "$schema": "https://opencode.ai/config.json",
  "model": "nexus-openrouter/provider/opaque-model-v9",
  "provider": {
    "nexus-openrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Nexus OpenRouter",
      "options": {
        "baseURL": "https://gateway.nexus.microvoid.io/providers/00000000-0000-0000-0000-000000000141",
        "apiKey": "{env:NEXUS_API_KEY}"
      },
      "models": {
        "provider/opaque-model-v9": {
          "name": "Provider opaque model"
        }
      }
    }
  }
}

Run

Terminalsh
export NEXUS_API_KEY="<NEXUS_INFERENCE_KEY>"
opencode

配置顶层 model 已选择 nexus-openrouter/provider/opaque-model-v9。也可以在 TUI 中运行 /models 并选择同一项;自定义 Provider 的配置语义以 OpenCode 官方文档为准。

Check your work

  • apiKey 只引用 {env:NEXUS_API_KEY},配置文件没有 Key 明文。
  • options 只包含 Nexus Gateway Base URL 和 Inference Key 引用。
  • Provider 配置的模型 Key 是原始上游模型名。
  • 平台方能按 Request ID、用户 Access 和 ProviderConnection 查看 Usage。
Navigation

Type to search…

↑↓ navigate↵ selectEsc close