Skip to content

OpenCode

Route OpenCode through Gate to add prompt-injection scanning, audit, caching, and cost tracking. Your workflow does not change. OpenCode reads its configuration from opencode.json in your project, or from ~/.config/opencode/opencode.json for every project. Each entry under provider names the npm package that speaks the wire, the connection details under options, and the models it offers. Create your Gate key (sk-gw-…) under API keys in the dashboard.

Pay through Gate

Use your Gate key as the only credential. Gate routes each request and bills your prepaid balance. Declare a gate provider on the OpenAI-compatible package and list the Gate-catalog models you want to see in OpenCode’s model picker.

{
"provider": {
"gate": {
"npm": "@ai-sdk/openai-compatible",
"name": "Constellation Gate",
"options": {
"baseURL": "https://gateway.constellationgate.ai/v1",
"apiKey": "sk-gw-…your Gate key…"
},
"models": {
"anthropic/claude-opus-4-8": { "name": "anthropic/claude-opus-4-8" }
}
}
}
}

The Gate key and the model are placeholders. Use your own key (sk-gw-…) and any Gate-catalog model, written provider/model. Browse IDs on the dashboard’s Models page or via GET /v1/models.

Use your own keys

Keep your own provider key (OpenRouter shown here). Gate forwards it and adds its security and audit layer underneath. options.apiKey stays your upstream key, and Gate’s two headers travel in options.headers: your Gate key in X-Gate-Api-Key, and the upstream’s base URL — without the /v1 OpenCode already sends — in X-Gate-Upstream-Url.

{
"provider": {
"openrouter-gate": {
"npm": "@ai-sdk/openai-compatible",
"name": "OpenRouter through Gate",
"options": {
"baseURL": "https://gateway.constellationgate.ai/v1",
"apiKey": "sk-or-…your OpenRouter key…",
"headers": {
"X-Gate-Api-Key": "sk-gw-…your Gate key…",
"X-Gate-Upstream-Url": "https://openrouter.ai/api"
}
},
"models": {
"openrouter/auto": { "name": "openrouter/auto" }
}
}
}
}

The provider id is yours to choose; a fresh one such as openrouter-gate leaves OpenCode’s own openrouter entry alone.

The model ids are not the same in the two modes. Paying through Gate, you write Gate-catalog ids (anthropic/claude-opus-4-8). With your own key, Gate forwards the model field to your upstream untouched, so every id under models has to be one your upstream’s own catalog defines — openrouter/auto here because that is OpenRouter’s id, but claude-opus-4-8, not anthropic/claude-opus-4-8, when the upstream is Anthropic direct. A Gate-catalog id sent to your own upstream is rejected by that upstream, which is the mistake to look for first if a model that appears in the picker never answers.

This covers any OpenAI-compatible upstream. An Anthropic key is the exception: Gate requires Claude traffic on the Anthropic /v1/messages wire, and @ai-sdk/openai-compatible speaks only the OpenAI wire. Send it from a provider built on @ai-sdk/anthropic instead, which does speak that wire — same options.headers, and the same https://gateway.constellationgate.ai/v1 as baseURL — or route a Claude key through Claude Code. Keep the /v1 on that baseURL: @ai-sdk/anthropic appends only /messages to it (its own default is https://api.anthropic.com/v1), and Gate forwards the path it receives onto the host in X-Gate-Upstream-Url, which stays https://api.anthropic.com without the /v1 — so the call lands on https://api.anthropic.com/v1/messages. A bare host as baseURL would send it to /messages and 404. The bare host in the Claude Code guide is correct there because Claude Code appends the whole /v1/messages itself.

Gate Connect writes this configuration for you, if you would rather not edit opencode.json by hand.

Confirm requests are flowing

Restart OpenCode so it reads the new config, pick the model you added from its model list, and open the dashboard. New requests appear on the Messages page within a few seconds, each with its model, cost, and security result.