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

@binux/llm-cost

v1.0.0

Published

πŸ’° Beautiful CLI to count tokens and estimate costs for any LLM model (Claude, GPT, Gemini, Mistral, and 300+ more). Auto-updates prices from OpenRouter.

Readme

llm-cost πŸ’°

Count tokens and estimate costs for any LLM model β€” right in your terminal.

npm version License: MIT Zero Dependencies

300+ models Β· Auto-updated prices Β· Zero dependencies Β· Beautiful CLI


✨ Features

  • πŸ”’ Accurate token counting β€” BPE-approximation, ~95% accuracy
  • πŸ’΅ Real-time pricing β€” auto-fetches latest prices from OpenRouter on every run
  • πŸ† Live Benchmarks β€” pulls daily ELO ratings directly from LMSYS Chatbot Arena
  • πŸ“Š Model Recommendations β€” smart match by category (code, chat, agents) and cost efficiency
  • 🎨 Beautiful interactive UI β€” colorized TUI with budget calculator and filtering
  • πŸ“¦ Zero dependencies β€” pure Node.js, nothing to install
  • πŸ”Œ Pipe-friendly β€” works with cat, echo, stdin
  • πŸ“š Library API β€” use programmatically in your own projects

Supported Providers

| Provider | Models | |----------|--------| | Anthropic | Claude Opus 4.5, Sonnet 4.5, Haiku 4.5, 3.7 Sonnet, 3.5 Sonnet/Haiku, 3 Opus | | OpenAI | GPT-4.1, GPT-4.1 Mini/Nano, GPT-4o, GPT-4o Mini, o3, o4-mini | | Google | Gemini 2.5 Pro/Flash/Flash-Lite, 2.0 Flash | | Meta | Llama 3.3 70B, 3.1 405B, 3.1 8B | | Mistral | Mistral Large, Small, Codestral | | xAI | Grok 3, Grok 3 Mini | | DeepSeek | DeepSeek R1, Chat V3 | | Cohere | Command R+, Command R | | + 300 more via auto-update from OpenRouter |


πŸš€ Install

npm install -g llm-cost

Or use without installing:

npx llm-cost

Requires Node.js 18+.


πŸ“– Usage

Interactive Mode (default)

Just run llm-cost with no arguments β€” perfect for beginners:

llm-cost

It will:

  1. Show a welcome screen with model count
  2. Let you type/paste your prompt
  3. Count tokens in real time
  4. Ask for expected output length
  5. Show a filterable comparison table

Quick Mode

# Count tokens and show costs for top models
llm-cost "Explain quantum computing in simple terms"

# Specific model
llm-cost "Hello world" -m claude-haiku

# Full comparison across ALL models
llm-cost "Write a 1000-word essay about AI" --compare

# Set expected output tokens
llm-cost "Translate this article" -o 2000

Pipe Mode

# From a file
cat my-prompt.txt | llm-cost

# From echo
echo "Hello, how are you?" | llm-cost

# From clipboard (macOS)
pbpaste | llm-cost

List Models

# All models with prices
llm-cost --list

# Filter by provider
llm-cost --list anthropic
llm-cost --list openai
llm-cost --list google

πŸ“¦ Programmatic API

const { countTokens, getModels, estimateCost, estimateAll } = require('llm-cost');

// Count tokens
const tokens = countTokens('Hello, world!');
console.log(tokens); // ~4

// Get all models (auto-fetches latest prices)
const models = await getModels();

// Estimate cost for one model
const cost = estimateCost({
  inputTokens: 1000,
  outputTokens: 500,
  model: models[0],
});
console.log(cost); // { inputCost, outputCost, totalCost }

// Compare all models at once
const { results } = await estimateAll({
  text: 'Your prompt here',
  outputTokens: 500,
});
// results sorted cheapest-first

πŸ”„ Auto-Update

Prices are automatically fetched from OpenRouter's public API on every run and cached for 1 hour. If you're offline, built-in fallback prices are used.

No API key required. No account needed.


πŸ›  CLI Reference

| Option | Description | |--------|-------------| | (no args) | Interactive mode | | "text" | Quick calc for top models | | -m, --model <name> | Calculate for a specific model (partial name OK) | | -o, --output <n> | Expected output tokens (default: auto) | | -c, --compare | Compare ALL models | | -l, --list [provider] | List models with prices | | -h, --help | Show help | | -v, --version | Show version |


🀝 Contributing

Contributions are welcome! Feel free to:

  • Add new model providers
  • Improve token counting accuracy
  • Suggest UI improvements
git clone https://github.com/YOUR_USERNAME/llm-cost.git
cd llm-cost
npm test

πŸ“„ License

MIT β€” use it however you want.