
# OpenCode

[OpenCode](https://opencode.ai/) is a terminal coding assistant. It
expects an OpenAI-compatible endpoint, which is what LowRouter
exposes.

## Configure

OpenCode reads its config from `~/.config/opencode/opencode.json`.
Point the OpenAI provider entry at LowRouter:

```json
{
  "providers": {
    "openai": {
      "baseURL": "https://api.lowrouter.ai/v1",
      "apiKey": "sk-lr-..."
    }
  },
  "defaultModel": "auto/mistralai/mistral-large-2512"
}
```

Restart OpenCode after editing the file.

## Picking a model

Inside OpenCode, run `/model` and pick from the list. If a model isn't
listed, type the LowRouter model ID directly — any model on the
[model browser](/models) is routable.

For coding tasks, name a capable model and let LowRouter pick where it
runs — `auto/mistralai/mistral-large-2512`. Choosing the model is
still yours:

- For long contexts: a model with ≥128K context window. The model
  browser tags context length per model.
- For latency-sensitive iteration: an `*-mini` or `*-haiku-*` variant.
- For careful reasoning: a top-tier reasoning model.

## Recommended setup

- **Dedicated key with a daily limit.** OpenCode is interactive and
  it's easy to lose track of how many tokens you spent in an
  afternoon. A daily limit on the key bounds the surprise.
- **Disable shell-execution tools by default.** OpenCode supports
  letting the model run shell commands; turn that off until you've
  reviewed the prompts the agent sends. Enable it per-session for the
  workflow that needs it.
- **Stream on.** Default in OpenCode; mentioned for completeness.

## Troubleshooting

- **Hangs on the first request**: confirm `baseURL` ends with `/v1`
  (no trailing slash). OpenCode appends `/chat/completions` itself.
- **Model "not found"**: the model isn't in OpenCode's autocomplete
  list, but it is routable. Run `/model auto/mistralai/mistral-large-2512`
  to confirm the gateway is reachable, then use the explicit model ID.
