---
title: "Draft OpenCode integration"
description: "Unverified draft settings for using OpenCode with minirouter."
canonical_url: "https://minirouter.sh/integrations/opencode"
markdown_url: "https://minirouter.sh/integrations/opencode.md"
last_updated: "2026-08-04"
---

# OpenCode + minirouter

Verification status: UNVERIFIED DRAFT
Confirm the current client fields and run the verification request before relying on this configuration.

Draft provider block for registering minirouter in OpenCode's JSON configuration.

Base URL: https://api.minirouter.sh/v1
Get a key: https://minirouter.sh/key

## Settings

opencode.json — project root, or ~/.config/opencode/opencode.json

1. Config file: opencode.json
   Use the draft block below as a starting point, then verify it against the installed version.
2. Environment: export MINIROUTER_KEY=mr-live-…
   The config reads the key from this env var.
3. Pick a model: /models → minirouter
   Inside OpenCode, /models lists the provider's models.

## Draft configuration

opencode.json — unverified draft

```
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "minirouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "minirouter",
      "options": {
        "baseURL": "https://api.minirouter.sh/v1",
        "apiKey": "{env:MINIROUTER_KEY}"
      },
      "models": {
        "meta/llama-3.3-70b": { "name": "Llama 3.3 70B" },
        "mistral/devstral-small-2": { "name": "Devstral Small 2" },
        "deepseek/deepseek-v3": { "name": "DeepSeek V3" },
        "meta/llama-4-maverick": { "name": "Llama 4 Maverick" }
      }
    }
  }
}
```

## Recommended models

Only use a model after confirming it appears in the live model catalog at https://minirouter.sh/api/v1/models.

- mistral/devstral-small-2: Coding-oriented candidate for edits and tool calls.
- meta/llama-3.3-70b: General-purpose candidate for agent tasks.
- deepseek/deepseek-v3: Reasoning-oriented candidate for multi-step work.
- meta/llama-4-maverick: Long-context candidate for larger repositories.

## Troubleshooting

### 404, HTML, or a parse error on every request

Almost always the base URL. Use https://api.minirouter.sh/v1 — the bare host without /v1 also works, but never append /chat/completions to the base URL field; the client adds that path itself.

Error reference: https://minirouter.sh/docs/errors#invalid_request

### 401 on every request

Wrong or rotated key. Keys start with mr-live-; after a rotation the old key keeps working for 24 hours, then dies.

Error reference: https://minirouter.sh/docs/errors#invalid_api_key

### 402 before any tokens arrive

Balance below the estimated cost of the request. Top up ($5 minimum) — and watch the x-minirouter-balance-usd header, the low-balance signal every response carries.

Error reference: https://minirouter.sh/docs/errors#insufficient_credits

### Provider missing from /models

OpenCode merges project and global config; a JSON syntax error makes the whole provider block vanish silently. Validate the file, then restart OpenCode.
