OpenCode

Add a custom OpenCode provider, connect its credentials, and select its model.

Install and prepare

  1. Install OpenCode using its official npm package below, then run opencode --version. Node.js and npm must be available.
  2. Create a routerra.ai key under API Keys. Copy a model ID permitted for that key from Models; the example uses the Chat Completions protocol and requires tool-call support for coding tasks.
npm install -g opencode-ai
opencode --version

Register and connect routerra

  1. Create or merge opencode.json in the project root. For all projects, use ~/.config/opencode/opencode.json instead. Replace every YOUR_MODEL_ID consistently; routerra/ is OpenCode’s provider prefix, not part of the upstream model ID.
  2. Start opencode, run /connect, choose Other, enter provider ID routerra, and paste your key. The ID must exactly match the JSON object key. Credentials are stored separately in ~/.local/share/opencode/auth.json. Run /models and select the configured model. Restart OpenCode after changing the configuration file.
{
  "$schema": "https://opencode.ai/config.json",
  "model": "routerra/YOUR_MODEL_ID",
  "provider": {
    "routerra": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "routerra.ai",
      "options": { "baseURL": "https://routerra.ai/v1" },
      "models": { "YOUR_MODEL_ID": { "name": "YOUR_MODEL_ID" } }
    }
  }
}

Check the connection

If the provider is missing, check which project/global config was loaded and whether provider.routerra.models is present. A saved key under a different /connect ID cannot authenticate this provider. For a /responses-only model, change npm to @ai-sdk/openai; the shown @ai-sdk/openai-compatible calls /chat/completions. Test a short reply and a read-only file query, then inspect routerra.ai usage for the chosen model.