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

@mrgoonie/openrouter-cli

v0.1.2

Published

OpenRouter CLI — agent + human friendly wrapper for the full OpenRouter API

Readme

openrouter

The all-in-one CLI for the OpenRouter API — agent-friendly by default.

Bun License Tests


Quickstart

# 1. Install
brew install openrouter/tap/openrouter

# 2. Authenticate
openrouter auth set-key sk-or-v1-...

# 3. Chat
openrouter chat send "What is the capital of France?" --model openai/gpt-4o

For agents — machine-readable JSON:

openrouter chat send "Summarize this" --model openai/gpt-4o --json --no-stream \
  <<< "$(cat document.txt)"
# stdout: { "schema_version": "1", "success": true, "data": { ... } }

Install

Homebrew (macOS / Linux)

brew install openrouter/tap/openrouter

Curl script

curl -fsSL https://raw.githubusercontent.com/mrgoonie/openrouter-cli/main/install.sh | sh

npm

npm install -g @mrgoonie/openrouter-cli

From source (requires Bun ≥ 1.1.38)

git clone https://github.com/mrgoonie/openrouter-cli
cd openrouter-cli
bun install
bun run build        # outputs bin/openrouter
./bin/openrouter --help

# Or run without building:
bun run dev -- --help

Configuration

The CLI resolves every config value from 6 sources in priority order:

| Priority | Source | Example | |----------|--------|---------| | 1 (highest) | CLI flag | --api-key sk-or-v1-... | | 2 | Environment variable | OPENROUTER_API_KEY=sk-or-v1-... | | 3 | .env file (dotenv cascade) | .env in cwd or parents | | 4 | TOML config file | ~/.config/openrouter/config.toml | | 5 | OS keychain | openrouter auth login | | 6 (lowest) | Built-in default | https://openrouter.ai/api/v1 |

Debug your config:

openrouter config doctor --json

Set values:

openrouter config set defaults.model openai/gpt-4o
openrouter config get defaults.model
openrouter config path   # print config file location

See .env.example for all recognized environment variables.


Commands

| Command | Description | |---------|-------------| | analytics show | Usage analytics by endpoint | | auth login | OAuth PKCE flow — stores key automatically | | auth set-key <key> | Manually store an API key | | auth status | Show resolved config + sources | | auth whoami | Verify credentials with a live API call | | chat send <msg> | Streaming chat completions | | completion | Shell completion (bash/zsh/fish) | | config doctor | Diagnose config resolution | | config get/set/unset | Read and write TOML config values | | credits show | Account credit balance | | embeddings create | Text embeddings | | generations get | Generation metadata by ID | | guardrails list/create/… | Manage content guardrails | | keys list/create/… | Manage API sub-keys | | models list | Browse available models | | org members | Organization member list | | providers list | Provider status | | rerank create | Rerank documents by relevance | | responses create | Responses API (beta) | | video create/status/wait/download | Async AI video generation |


Agent Mode

The CLI is designed to be called from scripts and AI agents.

JSON output

Every command supports --json for a stable envelope:

{
  "schema_version": "1",
  "success": true,
  "data": { ... },
  "error": null,
  "meta": { "request_id": "gen-...", "elapsed_ms": 312 }
}

Error envelope:

{
  "schema_version": "1",
  "success": false,
  "data": null,
  "error": { "code": "unauthorized", "message": "Invalid API key", "status": 401 },
  "meta": {}
}

NDJSON streaming

openrouter chat send "Write a haiku" --model openai/gpt-4o --output ndjson
# → one JSON object per line, tokens streamed as they arrive

Exit codes

| Code | Meaning | |------|---------| | 0 | Success | | 1 | Unexpected error | | 2 | Bad flags / missing args | | 64 | API key not set | | 65 | Unauthorized (HTTP 401) | | 66 | Forbidden (HTTP 403) | | 67 | Not found (HTTP 404) | | 68 | Insufficient credits (HTTP 402) | | 69 | Rate limited (HTTP 429) | | 70 | Server error (HTTP 5xx) | | 71 | Request timeout | | 72 | Unexpected API response shape | | 73 | Async video job failed / cancelled |

Check $? after every call. Exit codes are stable across patch versions.


Troubleshooting

No API key → exit 64

export OPENROUTER_API_KEY=sk-or-v1-...
# or:
openrouter auth set-key sk-or-v1-...

Management key required → exit 64

Commands like credits show, keys list, guardrails list need a separate management key:

export OPENROUTER_MANAGEMENT_KEY=sk-or-v1-...
# or:
openrouter auth set-key sk-or-v1-... --management

Rate limited → exit 69

The client retries automatically (up to 3 times with exponential backoff). If still hitting limits, reduce request frequency or add --timeout headroom.

SSE stream hangs

Add --no-stream to get a single blocking response instead:

openrouter chat send "hi" --model openai/gpt-4o --no-stream --json

Inspect full config resolution

openrouter config doctor

Claude Code plugin

This repo ships a Claude Code plugin that teaches agents how to drive the CLI with JSON envelopes, stable exit codes, NDJSON streaming, and common workflows (chat, embeddings, rerank, video).

# Inside Claude Code:
/plugin marketplace add https://github.com/mrgoonie/openrouter-cli
/plugin install openrouter@openrouter-cli

Source: plugins/openrouter · Marketplace manifest: .claude-plugin/marketplace.json.


Docs


Contributing

  1. git clone + bun install
  2. bun run dev -- --help — verify CLI starts
  3. bun run test — unit tests (no network)
  4. bun run test:integration — real-API tests (requires .env with OPENROUTER_API_KEY and/or OPENROUTER_MANAGEMENT_KEY; per-suite auto-skip if a key is missing)
  5. bun run lint && bun run typecheck — must be clean
  6. Read Code Standards before submitting a PR

Integration tests

Integration tests spawn the compiled CLI and hit the real OpenRouter API. They use free / cheap models (meta-llama/llama-3.2-1b-instruct:free, google/gemini-2.0-flash-lite-001, openai/text-embedding-3-small) to keep cost negligible.

  • Locally: put keys in .env, then bun run test:integration.
  • CI: configure OPENROUTER_API_KEY and OPENROUTER_MANAGEMENT_KEY as repo secrets. The Integration Tests workflow runs on push to main and via workflow_dispatch.

License

MIT © 2026