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

opencode-openrouter-sync

v1.8.1

Published

OpenCode plugin for OpenRouter model synchronization

Readme

OpenRouter Model Sync Plugin

npm version CI License: MIT

A plugin for OpenCode that automatically syncs available models from OpenRouter's public API to your global configuration.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

See CHANGELOG.md for version history.

Features

  • Automatic model sync on startup (once per 24 hours)
  • Manual sync via /openrouter-sync command
  • File-based caching for resilience
  • No API key required (uses public endpoint)
  • Only adds new models, never overwrites existing configurations

Installation

Option 1: From npm (recommended)

npm install -g opencode-openrouter-sync

Then add the plugin to your OpenCode config at ~/.config/opencode/opencode.json:

{
  "plugin": ["opencode-openrouter-sync"]
}

Option 2: From source

Clone this repository and build:

git clone https://github.com/tbui17/opencode-openrouter-sync.git
cd opencode-openrouter-sync
npm install
npm run build

Copy the built plugin to your OpenCode plugins directory:

mkdir -p ~/.config/opencode/plugins
cp dist/index.js ~/.config/opencode/plugins/openrouter-sync.js

Add to your config:

{
  "plugin": ["openrouter-sync"]
}

Usage

Quick Start

  1. Install the plugin:

    npm install -g opencode-openrouter-sync
  2. Add to your OpenCode config (~/.config/opencode/opencode.json):

    {
      "plugin": ["opencode-openrouter-sync"]
    }
  3. Restart OpenCode — models will sync automatically on first run.

Automatic Sync

The plugin automatically syncs models on first startup. After that, it checks if 24 hours have passed since the last successful sync and runs automatically when you start OpenCode.

Manual Sync

Run the manual sync command anytime:

/openrouter-sync

This forces an immediate sync regardless of when the last sync occurred.

Programmatic Usage

You can also use the sync functionality programmatically in your own code:

import { syncModels, fetchModels } from 'opencode-openrouter-sync/sync';

// Full sync with config
const result = await syncModels();
console.log(`Added ${result.added} models, skipped ${result.skipped}`);

// Fetch models without updating config
const models = await fetchModels();
console.log(`Fetched ${models?.length ?? 0} models from OpenRouter`);

Note: Programmatic functions are available via the /sync subpath to avoid conflicts with OpenCode's plugin loading mechanism.

Verifying Sync

After a sync, you can verify the models were added:

cat ~/.config/opencode/opencode.json | jq '.provider.openrouter.models | keys | length'

This should show a number greater than 400, representing all available OpenRouter models.

Viewing Synced Models

List all synced OpenRouter models:

cat ~/.config/opencode/opencode.json | jq '.provider.openrouter.models | to_entries | .[].key'

Check a specific model:

cat ~/.config/opencode/opencode.json | jq '.provider.openrouter.models["openai/gpt-4o"]'

Configuration

The plugin works out of the box without any configuration. However, you can customize behavior in your config file.

Default Config Location

  • Global config: ~/.config/opencode/opencode.json
  • Cache directory: ~/.local/share/opencode/openrouter-sync/cache.json

Configuration Options

Add options under provider.openrouter in your config:

{
  "plugin": ["opencode-openrouter-sync"],
  "provider": {
    "openrouter": {
      "options": {
        "cacheTtl": 86400000,
        "enabled": true
      }
    }
  }
}

| Option | Type | Default | Description | |--------|------|---------|-------------| | cacheTtl | number | 86400000 | Cache TTL in milliseconds (24 hours) | | enabled | boolean | true | Whether to run sync on startup |

How Models Are Added

The plugin adds models under provider.openrouter.models in your global config. Each model includes:

  • id - Model identifier
  • name - Human-readable name
  • contextWindow - Maximum context length
  • pricing - Input/output pricing information
  • max_completion_tokens - Maximum completion length
  • supported_parameters - Parameters the model supports
  • default_parameters - Default parameter values
  • is_moderated - Whether the model has content moderation enabled

Example model entry:

{
  "id": "openai/gpt-4o",
  "name": "GPT-4o",
  "contextWindow": 128000,
  "pricing": { "prompt": "2.50", "completion": "10.00" },
  "max_completion_tokens": 16384,
  "supported_parameters": ["temperature", "max_tokens", "top_p"],
  "default_parameters": { "temperature": 0.7 },
  "is_moderated": true
}
  • Only adds models that don't already exist
  • Never removes or overwrites existing models
  • Preserves any custom model configurations you have

Troubleshooting

Plugin Not Loading

  1. Check that the plugin file exists at ~/.config/opencode/plugins/openrouter-sync.js
  2. Verify the plugin is listed in your config under "plugin"
  3. Restart OpenCode after making config changes

Sync Not Running

  1. Check OpenCode logs for any error messages
  2. Verify you have internet access to reach openrouter.ai
  3. Try running /openrouter-sync manually to see error details

Models Not Appearing

  1. Run /openrouter-sync manually
  2. Check that ~/.config/opencode/opencode.json is writable
  3. Look for errors in the OpenCode console

Reset Cache

If you need to force a fresh sync:

rm ~/.local/share/openrouter-sync/cache.json

Then restart OpenCode or run /openrouter-sync.

Development

# Install dependencies
npm install

# Build the plugin
npm run build

# Run tests
npm test

# Clean build artifacts
npm run clean

License

MIT