---
title: "OpenCode + OpenRouter: connect, pick a model and control where prompts go — Aventail™ Guides"
url: https://aventail.co.uk/guides/opencode-openrouter
description: "Use OpenCode with OpenRouter: /connect and an API key, model IDs, opencode.json for OpenCode 1 and 2, provider routing, and what OpenRouter does with prompts."
lang: en-GB
---

Skip to content

Aventail™ co-founder speaks to BBC Radio Wales on AI safety and AI agents. Read the story: https://aventail.co.uk/newsroom/bbc-radio-wales-joseph-ward-ai-agents-safety

All guides (https://aventail.co.uk/guides)

# OpenCode + OpenRouter: connect, pick a model and control where prompts go

23 November 2026 12 min read

Use OpenCode with OpenRouter: /connect and an API key, model IDs, opencode.json for OpenCode 1 and 2, provider routing, and what OpenRouter does with prompts.

OpenCode has a built-in OpenRouter provider. Run `/connect`, choose OpenRouter, paste an API key, then pick a model with `/models`. No config file and no proxy are needed.

One key then reaches every model OpenRouter lists, under IDs of the form `openrouter/<author>/<model>`. OpenCode uses a native OpenRouter runtime and does not assume an Anthropic model, so the first-party restriction that applies to Claude Code does not apply here. Every prompt still leaves your machine: first to OpenRouter, then to the provider that serves the model. This guide covers the setup on OpenCode 2 and OpenCode 1, the config file, how to check which model answered, and the privacy settings to change before you open a private repository.

| | OpenCode with OpenRouter, as of 15 November 2026 |
| --- | --- |
| Connect | `/connect`, choose OpenRouter, paste the key. Or set `OPENROUTER_API_KEY` on the OpenCode server |
| Model IDs | `openrouter/` plus the OpenRouter slug, for example `openrouter/anthropic/claude-sonnet-5.5` |
| Config file | Optional. `opencode.json` or `opencode.jsonc` in the project, or `~/.config/opencode/` for all projects |
| Where the key is kept | OpenCode 2: the server's SQLite database. OpenCode 1: `~/.local/share/opencode/auth.json` |
| Price | Provider token prices with no markup, plus a 5.5% fee ($0.80 minimum) when you buy credits |
| Does OpenRouter store prompts | No, unless you opt in. It stores request metadata |
| Does the provider store or train on prompts | Depends on the endpoint. You filter providers in OpenRouter's privacy settings |
| Zero data retention | Per model group, per guardrail, or per request with `provider.zdr` |
| Region control | `eu.openrouter.ai` and `us.openrouter.ai`, on the Business and Enterprise plans |

## What you need

| | Minimum | Notes |
| --- | --- | --- |
| OpenCode | OpenCode 2 or OpenCode 1 | OpenCode's docs now describe OpenCode 2. It reads OpenCode 1 config files |
| OpenRouter account | An API key from openrouter.ai/settings/keys | Keys start with `sk-or-v1-` |
| Credits | Any balance | Free models work without credits, with daily limits |
| A model with tool calling | Required for edits and commands | OpenRouter's model list shows `tools` under supported parameters |

## Step 1: install OpenCode

OpenCode's own docs give these commands for OpenCode 2:

`curl -fsSL https://opencode.ai/v2/install | bash`

`npm install -g @opencode/cli`

`brew install anomalyco/tap/opencode-v2`

OpenRouter's guide still lists the earlier commands (`curl -fsSL https://opencode.ai/install | bash`, `npm install -g opencode-ai`, `brew install anomalyco/tap/opencode` ). OpenCode 1 and 2 both use the `opencode` command and are no longer installed side by side by default, so pick one. The desktop app is a separate download from opencode.ai/download.

## Step 2: create an OpenRouter key

Sign in at openrouter.ai, open the API Keys page, choose Create API Key and copy it. Add credits on the Credits page if you plan to use paid models.

## Step 3: connect OpenRouter

In the terminal app:

`/connect`

Search for OpenRouter, choose it and paste the key. To do the same without opening the TUI:

`opencode auth login`

That opens a provider picker. Entering an API key needs an interactive terminal.

For a server, a container or CI, give the key to the OpenCode process as an environment variable. OpenCode's docs name `OPENROUTER_API_KEY` for this provider and show two ways to set a provider variable. For a one-off private server:

`OPENROUTER_API_KEY=sk-or-v1-... opencode --standalone`

For the shared background service:

`opencode service set env OPENROUTER_API_KEY sk-or-v1-...`
`opencode auth list`

An environment connection appears in `auth list` with the type `environment`. A saved account takes precedence over it.

In the desktop app, open Settings, find OpenRouter under Providers in the Popular providers list, choose Connect, pick the API key method and paste the key. The terminal and desktop apps share the same credentials.

## Step 4: pick a model and set a default

`/models`

Many OpenRouter models are preloaded. The choice applies to the current session and does not change your config. To set the default for new work, add `model` to `opencode.json`:

`{`
`"$schema": "https://opencode.ai/config.json",`
`"model": "openrouter/anthropic/claude-sonnet-5.5"`
`}`

For one command-line run, pass the model as a flag:

`opencode run --model openrouter/anthropic/claude-sonnet-5.5 "Refactor parseToken"`

OpenRouter also has "latest" aliases that start with `~`, such as `~anthropic/claude-sonnet-latest`, which resolve to the newest model in a family. As a default that becomes `"model": "openrouter/~anthropic/claude-sonnet-latest"`.

## Step 5: add a model that is not in the picker

Add it under the OpenRouter provider in your config, with the OpenRouter slug as the key. OpenRouter's guide shows the OpenCode 1 form:

`{`
`"$schema": "https://opencode.ai/config.json",`
`"provider": {`
`"openrouter": {`
`"models": {`
`"~anthropic/claude-sonnet-latest": {},`
`"~google/gemini-flash-latest": {}`
`}`
`}`
`}`
`}`

OpenCode 2 renames the `provider` map to `providers`. OpenCode states that supported OpenCode 1 config keeps working in OpenCode 2, so either form loads there. Keep each provider entry entirely in one format. OpenRouter's guide says to restart OpenCode after the change.

## Step 6: restrict which providers serve your requests

OpenRouter picks a provider for each request by price, throughput, latency and reliability. To pin it, OpenRouter's guide adds its `provider` object to a model, in the OpenCode 1 form:

`{`
`"$schema": "https://opencode.ai/config.json",`
`"provider": {`
`"openrouter": {`
`"models": {`
`"~anthropic/claude-sonnet-latest": {`
`"options": {`
`"provider": {`
`"order": ["anthropic"],`
`"allow_fallbacks": true`
`}`
`}`
`}`
`}`
`}`
`}`
`}`

In native OpenCode 2 config, provider `options` are split into `settings`, `headers` and `body`, and `body` holds JSON fields merged into each request. OpenRouter's `provider` object is a request body field, so the OpenCode 2 form for every OpenRouter model is:

`{`
`"$schema": "https://opencode.ai/config.json",`
`"providers": {`
`"openrouter": {`
`"body": {`
`"provider": {`
`"zdr": true,`
`"data_collection": "deny"`
`}`
`}`
`}`
`}`
`}`

That block combines OpenCode's documented `body` field with OpenRouter's documented `provider` fields. Neither vendor shows the two together, so send one request and confirm the provider in OpenRouter's Activity page. A config file is also something a developer can edit. The account-level settings in the privacy section below apply whatever the client sends.

## Step 7: check which model answered

- `/models` shows the model selected for the session, and `opencode auth list` shows which connections are active.
- `opencode models` lists every model your install can use.
- OpenRouter's Activity page (openrouter.ai/activity) shows each request with its model. Opening a generation in Logs shows the provider, token counts and cost.

Use the OpenRouter side when the ID you typed is an alias or a router. A `~latest` alias resolves to whatever is newest, and a router such as `openrouter/auto-code` picks a model for every turn, so only OpenRouter's record shows what ran.

## What works and what does not

Works: chat, file edits, shell commands and subagents on any OpenRouter model that supports tool calling. Variants work by adding `#` and the variant ID, as in `openrouter/anthropic/claude-sonnet-5.5#high`; variant names depend on the model. Provider failover happens inside OpenRouter, so a rate limit at one provider does not end the session.

Does not work, or works differently:

- **Models appear only after a restart.** If the picker is empty right after you connect, quit OpenCode fully and reopen it.
- **A model without tool calling will chat but not act.** Check the model's supported parameters before you blame the config.
- **Credentials and config are scoped to a location.** OpenCode's docs note that a model available in one project may be unavailable in another.
- **Free models have limits.** OpenRouter allows 50 free-model requests a day, or 1,000 a day once you have bought at least 10 credits. Free endpoints have their own training switch in privacy settings.
- **OpenCode 2 changed the plugin API.** OpenCode 1 plugins do not run in OpenCode 2, which matters if you rely on a community plugin for OpenRouter.
- **OpenCode 2 reads outside the project without asking.** In OpenCode 2, `external_directory` is allowed by default. To keep the OpenCode 1 behaviour, add `{ "action": "external_directory", "resource": "*", "effect": "ask" }` to `permissions`. With a cloud model this decides what can be sent.

## What OpenRouter and the model provider do with your prompts

Two companies see each request.

| | OpenRouter | The provider behind it |
| --- | --- | --- |
| Stores prompts and responses | Not by default. Stores metadata: token counts, latency, model | Set per endpoint. OpenRouter labels each one: ZDR, Safety Retention, or Retention and Training |
| Trains on them | Only if you turn on "OpenRouter Use of Inputs/Outputs", which gives a 1% discount. Off by default | Providers that may train are not used unless you allow it in privacy settings. Paid and free models have separate switches |
| Opt-in logging | "Input & Output Logging" (beta). Stored for at least 3 months; organisation admins can read every logged request | Not applicable |
| Exceptions | All requests, including ZDR traffic, are screened for CSAM; flagged content may be kept | "Safety Retention" endpoints may keep any request to prevent abuse, with no training |

Where OpenRouter cannot establish a provider's policy, it assumes the endpoint retains and trains on data and marks it that way.

Settings to change before you open a private repository:

1. **Privacy settings** (openrouter.ai/settings/privacy). Leave the training switches off for paid and free models. Enforce ZDR for the model groups you use, and choose "ZDR only" or "Allow Safety Retention".
2. **Allowed providers.** Set an account-wide list of providers, also in privacy settings. If no provider on the list can serve a request, it fails with an error.
3. **Guardrails**, for an organisation. An admin can give a member or a key a model allowlist, a provider allowlist, a budget, ZDR and allowed data regions.
4. **Region.** On the Business and Enterprise plans, requests sent to `eu.openrouter.ai` are processed only in the EU/EEA, the UK and Switzerland. OpenCode lets you override the OpenRouter endpoint with `settings.baseURL` while keeping the native OpenRouter package; the regional API base is `https://eu.openrouter.ai/api/v1`.

ZDR covers model inference only. Plugins and server tools such as web search follow the policies of the services behind them.

## The same setup for a team: an approved provider under a routing rule

For a team, two controls exist without any extra product. OpenRouter guardrails limit what each key can reach. OpenCode `policies` can deny every provider except the one you approve, and a config file in the system directory (`/etc/opencode` on Linux) or a macOS managed preference outranks user and project files. Both controls still send every repository to the cloud.

Aventail ™ Connect configures OpenCode to send model requests through Aventail ™ Link, the inference engine and gateway on each machine. Routing rules are set once in Aventail ™ Control and evaluated on the device. A provider connection calls an approved cloud provider through your organisation's own account, with the key stored in Control's API key vault.

Aventail ™ connects to hosted providers through your organisation's own account with that provider. Google Gemini is one, and Aventail ™ 's site names Google and Anthropic models, Kimi, DeepSeek, Mistral and Qwen. With an approved provider, the pattern is:

1. **Install Link** on each machine and choose Connect next to OpenCode in Connected apps. Do not add an Aventail ™ provider inside OpenCode, and review any provider you added by hand so it does not conflict.
2. **Add the provider key** to the API key vault (Fleet Admin or Super Admin).
3. **Tag the machines.** Rules match devices, so machines that work on sensitive repositories get their own tag and policy.
4. **Write two policies.** Sensitive machines permit only On device. Other machines use On device first with one fallback hop to the approved provider.
5. **Check Requests in Control** after a harmless prompt. If no destination is permitted, the request fails with an error.

Routing to hosted providers is in beta. The hosted Control service receives device and routing events, and does not receive prompts or responses.

## Which path to take

| | OpenCode + OpenRouter by hand | OpenCode with Aventail ™ Connect |
| --- | --- | --- |
| Who it suits | One developer, or a team happy with OpenRouter as the gateway | A team that must keep some repositories on local models |
| Setup | `/connect` and a key | Connect button in Link, rules in Control |
| Model choice | Any OpenRouter model, chosen in OpenCode | Chosen in Link, within the routing rule |
| Where prompts go | OpenRouter, then a provider it selects | Where the rule says: the device, or one approved provider on your own account |
| Local models | No | Yes |
| Record of requests | OpenRouter Activity and Logs | Requests in Control |
| Cost | Provider prices plus 5.5% on credits | Free for three devices; Starter is £50 a month excluding VAT with ten devices; provider charges on your own account |

## Frequently asked questions

**Does OpenCode support OpenRouter?**
Yes. OpenRouter is a built-in provider with its own runtime package and catalogue. Connect it with `/connect` or by setting `OPENROUTER_API_KEY`.

**What is the model ID format for OpenRouter in OpenCode?**
The provider prefix `openrouter/` followed by the full OpenRouter slug, for example `openrouter/anthropic/claude-sonnet-5.5`. In the `models` map of a config file, use the slug alone as the key.

**Where does OpenCode store my OpenRouter key?**
OpenCode 2 stores saved keys in the server's SQLite database, usually `~/.local/share/opencode/opencode.db`; `opencode debug paths db` prints the path. OpenCode 1 used `~/.local/share/opencode/auth.json`, which OpenCode 2 imports during migration.

**Why are there no OpenRouter models after I connect?**
The provider catalogue loads at startup. Quit OpenCode fully and reopen it. If one model is missing, add it under the OpenRouter provider's `models` map and restart.

**Can I use free OpenRouter models in OpenCode?**
Yes, within OpenRouter's limits of 50 requests a day, or 1,000 a day after you buy at least 10 credits. Check the free-model training switch in privacy settings first.

**Does OpenRouter see my code?**
Your prompts pass through OpenRouter to the model provider. OpenRouter states it does not store prompts or responses unless you opt in to logging. The provider's own retention terms apply, which you can filter with ZDR and allowed providers.

**Is my opencode.json from OpenCode 1 still valid?**
OpenCode states that supported OpenCode 1 config keeps working in OpenCode 2 and is normalised in memory without rewriting the file. Plugins and integrations that call the server API are the parts that need porting.

## Related guides

- AI coding on your own models: https://aventail.co.uk/guides/ai-coding-on-your-own-models
- Claude Code + OpenRouter: https://aventail.co.uk/guides/claude-code-openrouter
- OpenCode + Ollama: https://aventail.co.uk/guides/opencode-ollama
- OpenCode + Gemini: https://aventail.co.uk/guides/opencode-gemini
- OpenCode with: https://aventail.co.uk/guides/opencode-with-aventail-connect
  Aventail: https://aventail.co.uk/guides/opencode-with-aventail-connect
  ™: https://aventail.co.uk/guides/opencode-with-aventail-connect Connect: https://aventail.co.uk/guides/opencode-with-aventail-connect
- OpenCode vs Claude Code: https://aventail.co.uk/guides/opencode-vs-claude-code

## Sources

1. OpenRouter, OpenCode integration: https://openrouter.ai/docs/cookbook/coding-agents/opencode-integration
2. OpenCode, Intro and installation: https://opencode.ai/docs/
3. OpenCode, Providers: https://opencode.ai/docs/providers/
4. OpenCode, CLI providers and credentials: https://opencode.ai/docs/cli/providers/
5. OpenCode, Models: https://opencode.ai/docs/models/
6. OpenCode, Config: https://opencode.ai/docs/config/
7. OpenCode, Migrate from V1: https://opencode.ai/docs/migrate-v1/
8. OpenCode, Policies: https://opencode.ai/docs/policies/
9. OpenCode, CLI commands: https://opencode.ai/docs/cli/commands/
10. models.dev, provider catalogue used by OpenCode: https://models.dev/api.json
11. OpenRouter, Data collection: https://openrouter.ai/docs/guides/privacy/data-collection
12. OpenRouter, Provider logging: https://openrouter.ai/docs/guides/privacy/provider-logging
13. OpenRouter, Zero data retention: https://openrouter.ai/docs/guides/features/zdr
14. OpenRouter, Provider routing: https://openrouter.ai/docs/guides/routing/provider-selection
15. OpenRouter, Guardrails: https://openrouter.ai/docs/guides/features/guardrails
16. OpenRouter, Input and output logging: https://openrouter.ai/docs/guides/features/input-output-logging
17. OpenRouter, In-region routing: https://openrouter.ai/docs/guides/features/in-region-routing
18. OpenRouter, Auto Code router: https://openrouter.ai/docs/guides/routing/routers/auto-code
19. OpenRouter, FAQ (fees, free model limits, logging): https://openrouter.ai/docs/faq
20. OpenRouter, model list API: https://openrouter.ai/api/v1/models
21. Aventail ™, Connect overview: https://docs.aventail.co.uk/docs/connect/overview
22. Aventail ™, Routing: https://docs.aventail.co.uk/docs/fleet/routing
23. Aventail ™, OpenCode with Aventail ™ Connect: https://aventail.co.uk/guides/opencode-with-aventail-connect
24. Aventail ™, Pricing: https://aventail.co.uk/#pricing

All sources were read on 15 November 2026.

We use optional cookies and tracking to identify visiting companies, load our contact form, measure Google Ads download clicks and understand page use with PostHog on our homepage, Connect and How it works pages, Ollama and LM Studio comparison guides and campaign pages. Cookie policy (https://aventail.co.uk/cookies)

## Structured data

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Organization",
      "@id": "https://aventail.co.uk/#organization",
      "name": "Aventail",
      "alternateName": "Locai",
      "legalName": "Loc.ai Ltd",
      "description": "Aventail, formerly Locai, was founded in 2026 and is a graduate of Google AI First. It gives enterprises the full AI stack to adopt AI securely: a built-in inference engine, deployment of supported models across approved hardware, on-device classification and policy-based routing between those machines and approved external AI providers, central management and an employee workspace. Organisations use Aventail to put approved information to work while controlling where inference requests run.",
      "url": "https://aventail.co.uk/",
      "logo": "https://aventail.co.uk/apple-touch-icon.png",
      "email": "hello@aventail.co.uk",
      "hasCredential": [
        {
          "@type": "EducationalOccupationalCredential",
          "name": "Cyber Essentials",
          "credentialCategory": "certification",
          "url": "https://aventail.co.uk/trust#cyber-essentials"
        }
      ]
    },
    {
      "@type": "Article",
      "@id": "https://aventail.co.uk/guides/opencode-openrouter#page",
      "url": "https://aventail.co.uk/guides/opencode-openrouter",
      "name": "OpenCode + OpenRouter: connect, pick a model and control where prompts go",
      "description": "Use OpenCode with OpenRouter: /connect and an API key, model IDs, opencode.json for OpenCode 1 and 2, provider routing, and what OpenRouter does with prompts.",
      "publisher": {
        "@id": "https://aventail.co.uk/#organization"
      },
      "headline": "OpenCode + OpenRouter: connect, pick a model and control where prompts go",
      "datePublished": "2026-11-23",
      "dateModified": "2026-11-23T19:37:53.694136+00:00",
      "image": "https://aventail-ai-platform.lovable.app/images/share/og-home-v7.jpg",
      "author": {
        "@id": "https://aventail.co.uk/#organization"
      }
    },
    {
      "@type": "BreadcrumbList",
      "@id": "https://aventail.co.uk/guides/opencode-openrouter#breadcrumb",
      "itemListElement": [
        {
          "@type": "ListItem",
          "position": 1,
          "name": "Home",
          "item": "https://aventail.co.uk/"
        },
        {
          "@type": "ListItem",
          "position": 2,
          "name": "Guides",
          "item": "https://aventail.co.uk/guides"
        },
        {
          "@type": "ListItem",
          "position": 3,
          "name": "OpenCode + OpenRouter: connect, pick a model and control where prompts go",
          "item": "https://aventail.co.uk/guides/opencode-openrouter"
        }
      ]
    }
  ]
}
```