openrouter-usage
v0.1.0
Published
Bun-first CLI for one-time OpenRouter usage snapshots
Readme
openrouter-usage
A small Bun-first TypeScript CLI that fetches and prints a one-time OpenRouter usage snapshot.
Requirements
- Bun installed (
bun --version) - An OpenRouter API key
Install dependencies
bun installRun from source
bun run src/cli.ts usageUse the CLI key from environment
export OPENROUTER_API_KEY="sk-..."
bun run src/cli.ts usageReuse the key from opencode
If ~/.local/share/opencode/auth.json exists and contains:
{
"openrouter": {
"type": "api",
"key": "sk-..."
}
}the CLI will use that key automatically before falling back to OPENROUTER_API_KEY.
Use a key for one invocation
bun run src/cli.ts usage --key "sk-..."The key input is normalized (trims whitespace and strips wrapping single/double quotes).
Optional request configuration
--base-url <url>orOPENROUTER_API_URL--referrer <url>orOPENROUTER_HTTP_REFERER--title <title>orOPENROUTER_X_TITLE
Example:
export OPENROUTER_API_KEY="sk-..."
export OPENROUTER_HTTP_REFERER="https://example.com"
export OPENROUTER_X_TITLE="My CLI"
bun run src/cli.ts usage --base-url "https://openrouter.ai/api/v1"Run via package bin name
The package bin is openrouter-usage and points to src/cli.ts (Bun shebang).
If installed globally in a Bun-compatible environment, run:
openrouter-usage usageDevelopment scripts
bun run lint
bun run formatExit codes
0success1any error (missing key, API error, network error, parse error)
