# OpenCode

> Run Claude Code's roles on the OpenCode subscription, its DeepSeek, GLM, Kimi, Qwen and MiniMax models, with one endpoint and an API key.
>
> Run Claude Code's roles on OpenCode's DeepSeek, GLM, Kimi, Qwen and MiniMax models. You need an OpenCode API key.

OpenCode's subscription serves open-weight models from several vendors behind one OpenAI-compatible URL, `https://opencode.ai/zen/go`. `sc` reaches it as the `opencode` endpoint with your API key, and the gateway translates each request.

1. Save your OpenCode key

   ```sh
   printf '%s\n' '<your-opencode-key>' > ~/.opencode-go
   chmod 600 ~/.opencode-go
   ```

   The gateway reads `~/.opencode-go` on every request, so a changed key needs no restart.

2. Add a profile

   ```toml
   [profiles.flash]
   opus = { slug = "opencode/deepseek-v4.1-flash", reasoning = { effort = "high" } }
   ```

   The model id is the part of the slug after `opencode/`. The `config.toml` that `sc system` writes on first run already has the `opencode` endpoint, so add the profile to it.

3. Check the routing

   ```sh
   sc profiles flash
   ```

   The listing shows one row per role, with the model it is sent to.

4. Launch with it

   ```sh
   sc -u flash <project> <agent>
   ```

   Claude Code starts with the `opus` role on DeepSeek.

This `flash` profile is a full gateway: every role runs on DeepSeek and your Claude login is not used ([what changes](/docs/models#how-roles-map-to-models)). To keep Claude on the main loop and send only subagents to OpenCode, use the [recommended profile](/docs/custom-profiles#recommended-profile-walkthrough), whose `sonnet` and `haiku` rows point at `opencode/deepseek-v4.1-flash`.

**Use a profile that is already in my config**

The first-run `config.toml` has four profiles that use the `opencode` endpoint, named `claude-flash` (the recommended one), `fast`, `coding` and `research`. Run `sc profiles` to list them, then launch one by name, for example `sc -u claude-flash <project> <agent>`. Edit an existing table rather than adding a second one with the same name.

**My config has no opencode endpoint**

Add the endpoint next to your profiles:

```toml
[endpoints.opencode]
url = "https://opencode.ai/zen/go"
format = "openai-compat"
auth = "bearer"
key_file = "~/.opencode-go"
```

**Pick a model id**

OpenCode publishes its live list:

```sh
curl -s https://opencode.ai/zen/go/v1/models
```

Most models use `openai-compat`. The Qwen `*-max` models need the Anthropic wire, so their row sets `format = "anthropic-messages"` and `auth = "x-api-key"` ([per-model overrides](/docs/provider-openai-compatible#per-model-wire-overrides)). The gateway sends a thinking field for DeepSeek, GLM, Kimi, Qwen, MiniMax and MiMo ids, and none for other ids ([reasoning by model](/docs/custom-profiles#write-your-own-profile)).

**Read the key from the environment**

Replace `key_file` with `key_csv = "${OPENCODE_API_KEY}"`, and keep only one of the two: a `key_file` that cannot be read fails the launch even when `key_csv` is set. The daemon expands the variable in its own environment ([details](/docs/gateways#keys-from-the-environment)).

**Tell whether my key is wrong**

OpenCode's model list is public, so the launch check cannot reject a wrong key. A bad key surfaces as a `401` on the first request that reaches OpenCode.

**See my OpenCode usage**

`sc` does not meter OpenCode. `sc usage` lists the endpoint as `usage not queryable via API key — see opencode.ai console`, and the status line shows no dollar figure for it, because the endpoint has no `rates` table. Check your plan's usage on opencode.ai.

**Use OpenCode Zen**

OpenCode Zen, the pay-as-you-go API with a different catalog, lives at `https://opencode.ai/zen`. Declare it as a second endpoint under another name, such as `[endpoints.opencode-zen]`, with the same `format`.
