Integrations

OpenCode

Run the open-source terminal agent on any model in the MiniRouter catalog.

OpenCode is an open-source coding agent for the terminal. Register MiniRouter as an OpenAI-compatible provider to run it on any tool-capable model in the catalog, a preset or a router, with one balance and per-key spend limits.

1. Install OpenCode

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

2. Export your key

Create a key, then export it in the shell that launches OpenCode.

~/.zshrc or ~/.bashrc
export MINIROUTER_KEY=mr-live-YOUR-KEY-HERE

3. Add the provider

Add MiniRouter to your global config. {env:MINIROUTER_KEY} keeps the key out of the file.

~/.config/opencode/opencode.json
{
  "$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": {
        "zai/glm-5.3-flash": { "name": "GLM 5.3 Flash" },
        "openai/gpt-5.6-sol": { "name": "GPT 5.6 Sol" },
        "spacexai/grok-4.6": { "name": "Grok 4.6" },
        "google/gemini-3.8-flash": { "name": "Gemini 3.8 Flash" }
      }
    }
  }
}

4. Pick a model

Terminal
opencode

Run /models, choose a MiniRouter model and send a prompt. Then open Activity. The request lists its model, tokens and exact cost.

Choose models

/models lists only the models in your provider block. Add routers and presets there too.

opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "minirouter/zai/glm-5.3-flash",
  "small_model": "minirouter/minirouter/auto:cheap",
  "provider": {
    "minirouter": {
      "models": {
        "minirouter/auto:code": { "name": "Auto code" },
        "minirouter/auto:cheap": { "name": "Auto cheap" },
        "@preset/your-slug": { "name": "My preset" }
      }
    }
  }
}
model
The default model.
small_model
Titles and other light tasks.
provider.minirouter.models
What /models lists.
  • minirouter/auto:code picks a model with reliable tool calling. See Auto router.
  • minirouter/auto:cheap picks the cheapest model that still answers well.
  • @preset/your-slug runs your saved preset. Edit it in Presets.

Run opencode models minirouter to print the list OpenCode loaded.

Global and project config

  • ~/.config/opencode/opencode.jsonThe MiniRouter provider block.
  • opencode.jsonmodel for this repository. Safe to commit.

OpenCode merges both files. Project keys win where they overlap.

Run headless

opencode run runs one prompt without the TUI. Use it in scripts and CI, or see Automatic code review for a pull request workflow.

Terminal
opencode run -m minirouter/zai/glm-5.3-flash \
  --format json "Run the tests and fix failures"
-m
Model, as provider/model.
--format json
Prints raw JSON events.
--auto
Approves permissions without asking.

Keep spend in check

Restrict models or filter content with Guardrails.

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: 400 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: 401 invalid_api_key.

402 before any tokens arrive

Balance below the estimated cost of the request. Top up (from $0.50 with direct Solana payments) — and watch the x-minirouter-balance-usd header, the low-balance signal every response carries.

Error: 402 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.

Every error code, with its fix: Errors.

Next steps

Esc