# OpenCode

Local V2 TUI; preserve an existing V1 configuration.

Source: https://zrelay.net/docs/agents/coding-agents/opencode/

## Manual setup

1. Check opencode --version. For V2 merge the JSON below into ~/.config/opencode/opencode.json or the existing .jsonc. Add an unused provider ID zrelay-gpt; preserve other providers and defaults.

2. Open /connect > Zrelay GPT and enter the key locally. Then /models > zrelay-gpt/gpt-5.5. Alternatively add env: ["ZRELAY_API_KEY"] to that provider, or settings.apiKey: "{env:ZRELAY_API_KEY}"; the server process must inherit the secret.

3. For an existing V1 file retain provider/npm/options and npm="@ai-sdk/openai-compatible"; do not migrate automatically. V2 uses providers/package/settings. For Claude use an isolated zrelay-claude provider, @opencode/ai/providers/anthropic-compatible, claude-sonnet-4-6 and https://api.zrelay.net/v1: this adapter adds /messages. Responses uses @opencode/ai/providers/openai-compatible/responses.

4. Inspect model visibility without sending a message. The example gpt-5.5 supports Chat Completions in Flex; select a key for the matching provider/pool. Grok variant: grok-4.5 with an isolated Chat Completions provider.

## Configuration and commands

```
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "zrelay-gpt": {
      "name": "Zrelay GPT",
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://api.zrelay.net/v1" },
      "models": {
        "gpt-5.5": {
          "name": "GPT-5.5",
          "limit": { "context": 128000, "input": 128000, "output": 4096 }
        }
      }
    }
  }
}
```

## Alternative: ask an AI assistant

Copy this complete prompt into your coding assistant. It describes configuration work; installation and paid tests need your authorization.

```
Set up Zrelay in my installed local OpenCode. Detect OS, OpenCode version, configuration format and server mode first. Read https://opencode.ai/docs/providers/, /docs/config/, /docs/cli/providers/, /docs/migrate-v1/ and https://keys.zrelay.net/api/catalog. Select an enabled model/path/pool authorized by my key; ask which provider/pool I own if unknown, never ask for the key. Merge one isolated Zrelay provider into existing configuration, preserving all unrelated settings and logins. Use the version-appropriate package and exact API protocol; OpenCode's Anthropic runtime needs https://api.zrelay.net/v1. Respect gateway token limits. Prefer local /connect secret entry, or an existing server-side ZRELAY_API_KEY; never read, print, log or embed credentials in config or chat. Validate syntax/schema and model visibility without inference. Ask my explicit consent before installing/upgrading anything or making paid calls. Report changed files, selected model/route and checks performed; do not claim streaming or tool-loop compatibility without testing.
```

## Limits and verification

128000 context is a conservative client budget; output is capped at 4096. A variable set in another terminal does not update a shared server. V1 and V2 schemas differ. Streaming and tools require separate runtime validation.

These recipes were reviewed against documentation and public catalog data. No client installation, authenticated request, paid inference, streaming or tool loop was executed. Validate configuration first; a later short text test does not establish complete agent compatibility.

Recheck the [live catalog](https://keys.zrelay.net/api/catalog) and your key’s provider/pool. The reviewed examples have 128000 input and 4096 output maxima unless a client limitation above prevents controlling the request. Never print, log or commit credentials.

## Official sources

Documentation checked 2026-11-09; mutable sources can differ from your installed version.

[https://opencode.ai/docs/migrate-v1/](https://opencode.ai/docs/migrate-v1/)

[https://opencode.ai/docs/config/](https://opencode.ai/docs/config/)

[https://opencode.ai/config.json](https://opencode.ai/config.json)

[https://opencode.ai/docs/cli/providers](https://opencode.ai/docs/cli/providers)

[https://opencode.ai/docs/providers/](https://opencode.ai/docs/providers/)

[https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/ai/src/protocols/anthropic-messages.ts](https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/ai/src/protocols/anthropic-messages.ts)

[https://keys.zrelay.net/api/catalog](https://keys.zrelay.net/api/catalog)

[https://opencode.ai/docs/models/](https://opencode.ai/docs/models/)

[https://keys.zrelay.net/api/catalog](https://keys.zrelay.net/api/catalog)
