npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dendaio/opencode-9router-plugin

v1.1.2

Published

OpenCode plugin for OpenAI-compatible auto model discovery

Downloads

711

Readme

opencode-9router-plugin

OpenCode plugin for 9router and other OpenAI-compatible gateways.

It auto-discovers models from GET /v1/models, maps them to OpenCode provider.models, enriches metadata from https://models.dev/api.json, supports filtering, and falls back to static models when discovery is unavailable.

Install and use in OpenCode

  1. Add plugin and API URL to your OpenCode config (~/.config/opencode/opencode.json):
{
  "plugin": ["@dendaio/opencode-9router-plugin"],
  "provider": {
    "9router": {
      "api": "https://your-gateway.example/v1"
    }
  }
}
  1. Login and set credentials:
opencode auth login

or inside OpenCode:

/connect 9router

During login, OpenCode asks for:

  • API key
  1. Restart OpenCode, then verify:
/models

You should see models under provider 9router.

Why provider entry matters

OpenCode only calls provider.models for providers present in the provider section (singular key: "provider").

This plugin auto-registers the provider key during login. Ensure provider.9router.api is set:

{
  "plugin": ["@dendaio/opencode-9router-plugin"],
  "provider": {
    "9router": {
      "api": "https://your-gateway.example/v1"
    }
  }
}

Configuration

Provider key must match plugin provider id (default: 9router).

{
  "plugin": ["@dendaio/opencode-9router-plugin"],
  "provider": {
    "9router": {
      "api": "https://your-gateway.example/v1",
      "options": {
        "modelEnrichment": {
          "enabled": true,
          "catalogURL": "https://models.dev/api.json",
          "timeoutMs": 3000,
          "cacheTtlMs": 600000,
          "overrideUpstream": false,
          "defaultContextWindow": 128000,
          "defaultMaxOutputTokens": 8192,
          "providerAliases": {
            "gh": "github",
            "cx": "openai",
            "ag": ["google-vertex", "google-vertex-anthropic"]
          }
        },
        "modelFiltering": {
          "includePrefixes": ["gh", "cx", "cc"],
          "excludePrefixes": ["ag"],
          "includeModelIdRegex": "/^(gpt|o\\d)/i",
          "excludeModelIdRegex": "/audio|embedding/i"
        }
      },
      "models": {
        "gpt-4o-mini": {
          "id": "gpt-4o-mini",
          "name": "gpt-4o-mini",
          "family": "gpt-4o",
          "release_date": "2024-07-18",
          "attachment": false,
          "reasoning": false,
          "temperature": true,
          "tool_call": true,
          "limit": { "context": 128000, "output": 8192 }
        }
      }
    }
  }
}

Enrichment behavior

  • Runtime enrichment fetches directly from https://models.dev/api.json (or your modelEnrichment.catalogURL).
  • Upstream fields win by default; set modelEnrichment.overrideUpstream: true to prefer models.dev values.
  • If no match is found, plugin uses safe defaults for capabilities and token limits.

Model filtering

Use these options under provider.9router.options.modelFiltering:

  • includePrefixes
  • excludePrefixes
  • includeModelIdRegex
  • excludeModelIdRegex

Example: exclude quality suffix variants.

{
  "provider": {
    "9router": {
      "options": {
        "modelFiltering": {
          "excludeModelIdRegex": "(-high|-low|-none|-xhigh)$"
        }
      }
    }
  }
}

Environment variables

Create .env from .env.example:

cp .env.example .env

Default key:

  • ROUTER9_API_KEY

Development

Use this workflow for local plugin development from source.

1) Install and build

npm install -g opencode-ai
npm install
npm run build

2) Point OpenCode to local build

Use absolute path to dist/index.js in ~/.config/opencode/opencode.json:

{
  "plugin": ["/workspaces/opencode-9router-connector/dist/index.js"],
  "provider": {
    "9router": {}
  }
}

3) Run watch mode

Terminal 1:

npm run dev

Terminal 2:

opencode

Restart OpenCode after rebuilds to pick up new plugin output.

4) Verify during development

Inside OpenCode:

/connect 9router
/models

5) Debug logs

OPENCODE_LOG=debug opencode

Troubleshooting

  • 401 Unauthorized: check ROUTER9_API_KEY (or your configured key source) and gateway auth requirements.
  • 404 Not Found: check provider.9router.api in opencode.json; plugin calls {api}/models if URL ends with /v1, otherwise {api}/v1/models.
  • No discovered models: plugin keeps static fallback models when fetch fails, schema is invalid, or provider.9router.api is missing.

License

MIT