---
title: "OpenCode"
description: "Configure OpenCode with the tested Nexus OpenAI-compatible provider fixture."
---

> Documentation Index
> Fetch the complete documentation index at: https://nexus.microvoid.io/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode

## 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 字段。


```json title="opencode.json"
{
  "$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

```sh title="Terminal"
export NEXUS_API_KEY="<NEXUS_INFERENCE_KEY>"
opencode
```

配置顶层 `model` 已选择 `nexus-openrouter/provider/opaque-model-v9`。也可以在 TUI 中运行 `/models` 并选择同一项；自定义 Provider 的配置语义以 [OpenCode 官方文档](https://opencode.ai/docs/providers)为准。

## Check your work

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

> **Executable source**
>
> 配置块由 `tests/e2e/fixtures/opencode.json` 生成。E2E 使用该配置的 Base URL、环境 Key 和模型表对 Node 与 Cloudflare
> Gateway 发起实际 Fake Provider 请求。

Source: https://nexus.microvoid.io/docs/make-model-requests/opencode/index.mdx
