Skip to main content
Watch: I Built an AI App Without Leaving Databricks

Setup guide - Documented by OpenRouter

Use OpenRouter in OpenCode

OpenCode has OpenRouter as a built-in provider. You connect it with /connect in the TUI or under Settings > Providers in the desktop app, and can add any OpenRouter slug under provider.openrouter.models in opencode.json. OpenRouter publishes an official guide for this setup.

Last verified 9 steps2 official sources

Steps

  1. Step 1.

    Install OpenCode.

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

    Or install with npm or Homebrew.

    Terminal
    npm install -g opencode-ai
    brew install anomalyco/tap/opencode
  3. Step 3.

    Start OpenCode in your project directory.

    Terminal
    cd /path/to/your/project
    opencode
  4. Step 4.

    Run /connect, search for OpenRouter, and paste your OpenRouter API key when prompted.

    Snippet
    /connect
  5. Step 5.

    Run /models to pick a model. Many OpenRouter models are preloaded.

    Snippet
    /models
  6. Step 6.

    Optional: add more OpenRouter models in opencode.json, using the OpenRouter slug as the key.

    JSON
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "openrouter": {
          "models": {
            "~anthropic/claude-sonnet-latest": {},
            "~google/gemini-flash-latest": {}
          }
        }
      }
    }
  7. Step 7.

    Optional: set a default model. OpenCode model ids are provider_id/model_id, so prefix the slug with openrouter/.

    JSON
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "openrouter/~anthropic/claude-sonnet-latest"
    }
  8. Step 8.

    Optional: write the key directly to ~/.local/share/opencode/auth.json.

    JSON
    {
      "openrouter": {
        "type": "api",
        "key": "sk-or-v1-your-key-here"
      }
    }
  9. Step 9.

    Check that the credential was stored.

    Terminal
    opencode auth list

Caveats

  • OpenCode handles the OpenRouter endpoint itself as a built-in provider. You set no base URL.
  • The leading ~ in slugs such as ~anthropic/claude-sonnet-latest is intentional. These are OpenRouter latest aliases.
  • If no OpenRouter models show up after connecting, fully quit and restart OpenCode. The provider catalog is read at startup.
  • Desktop app: Settings > Providers > OpenRouter > Connect > API key. The desktop app and the terminal share one set of credentials.

FAQ

How do I use OpenRouter in OpenCode?

OpenCode has OpenRouter as a built-in provider. You connect it with /connect in the TUI or under Settings > Providers in the desktop app, and can add any OpenRouter slug under provider.openrouter.models in opencode.json. OpenRouter publishes an official guide for this setup.

Which OpenRouter model ids work in OpenCode?

The official docs read for this guide list ~anthropic/claude-sonnet-latest, ~google/gemini-flash-latest, openrouter/~anthropic/claude-sonnet-latest and anthropic/claude-sonnet-4.5.

Is this an official OpenRouter and OpenCode setup?

OpenRouter documents this setup in its own docs. It was last checked against 2 official pages on October 17, 2026.

Sources

Last verified against 2 official pages.

Newsletter

New models, set up the day they ship

One email per week. New model releases, the coding tools that support them and how to wire them up.