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

llm-cost-estimator-now

v0.1.0

Published

Estimate token usage and cost across OpenAI, Anthropic, Gemini and more — as a library, CLI, and terminal dashboard.

Readme

llm-cost-estimator

Estimate token usage and cost across OpenAI, Anthropic, Gemini, and more — as a programmatic Node.js library, CLI tool, and terminal dashboard.

Features

  • Offline Token Counting: Accurate token estimation offline (using js-tiktoken for OpenAI and fine-tuned word/char heuristics for Anthropic/Gemini).
  • Offline Cost Logic: Bundles rates for popular models and merges them with optional local JSON overrides.
  • Library API: Clean, well-typed programmatic API for TypeScript and JavaScript.
  • CLI Commands: Direct CLI tool for one-off estimations, piping/logging usage in shell scripts, and CI/CD cost budget checks.
  • Interactive Terminal Dashboard: Real-time terminal dashboard built with React and Ink that watches log files and refreshes usage stats.

Installation

npm install llm-cost-estimator

To run the CLI tool globally:

npm install -g llm-cost-estimator

Programmatic Library Usage

1. Cost & Token Estimation

import { estimateCost } from 'llm-cost-estimator';

const result = estimateCost({
  provider: 'openai',
  model: 'gpt-4o-mini',
  input: 'Translate the following phrase: Hello, how are you today?',
  expectedOutputTokens: 150
});

console.log(result);
/*
{
  provider: 'openai',
  model: 'gpt-4o-mini',
  inputTokens: 11,
  outputTokens: 150,
  inputCost: 0.00000165,
  outputCost: 0.00009,
  totalCost: 0.00009165,
  currency: 'USD',
  pricingSource: 'bundled',
  estimated: false
}
*/

2. Model Comparison

Compare cost across multiple candidate models to select the best/cheapest option:

import { compareModels } from 'llm-cost-estimator';

const results = compareModels({
  input: 'Draft a short email.',
  expectedOutputTokens: 100,
  candidates: [
    { provider: 'openai', model: 'gpt-4o' },
    { provider: 'openai', model: 'gpt-4o-mini' },
    { provider: 'anthropic', model: 'claude-3-5-sonnet' }
  ]
});

// Results are returned sorted from cheapest to most expensive
console.log(results);

3. Usage Logging & Summarization

Log runs to a local .jsonl log file and generate aggregate statistics:

import { logUsage, getUsageSummary } from 'llm-cost-estimator';

// Log actual API consumption post-request
logUsage({
  provider: 'openai',
  model: 'gpt-4o',
  inputTokens: 850,
  outputTokens: 250,
  tag: 'production-v1'
});

// Fetch summary grouped by model, provider, tag, or day
const summary = getUsageSummary({
  groupBy: 'model',
  since: '24h' // accepts '24h', '7d', '30d' or Date object
});

CLI Usage

1. Estimate Cost

Estimate tokens and cost for a prompt directly:

llm-cost estimate -p openai -m gpt-4o-mini -i "Hello world" -o 50

Read input from a text file:

llm-cost estimate -p openai -m gpt-4o -f prompt.txt -o 100

Pipe stdin:

cat prompt.txt | llm-cost estimate -p anthropic -m claude-3-5-sonnet -o 200

Add a max cost constraint for CI/CD checks:

llm-cost estimate -p openai -m gpt-4o -i "Perform a complex build" --max-cost 0.005

Output results as JSON:

llm-cost estimate -p openai -m gpt-4o -i "Query" --json

2. Compare Models

Compare pricing for a prompt across several candidate models:

llm-cost compare openai/gpt-4o openai/gpt-4o-mini anthropic/claude-3-5-sonnet -i "Compare performance of these systems"

3. Log Usage

Manually append a run to the usage log:

llm-cost log -p openai -m gpt-4o -i 1000 -o 400 --tag release-test

4. Summary

Print tabular summaries of logged runs:

llm-cost summary --group-by model --since 7d

5. Interactive Dashboard

Open the live-updating terminal usage dashboard (built with Ink and React):

llm-cost dashboard

Configuration & Pricing Overrides

You can override default pricing rates or define new models by creating a JSON configuration file.

By default, the library looks for overrides at ~/.llm-cost-estimator/pricing-override.json. You can also point to a custom file via the LLM_COST_PRICING_OVERRIDE environment variable.

Example override structure:

{
  "currency": "USD",
  "models": {
    "openai/gpt-4o": {
      "inputPer1M": 2.00,
      "outputPer1M": 8.00
    },
    "custom-provider/my-new-model": {
      "inputPer1M": 1.00,
      "outputPer1M": 4.00
    }
  }
}

License

MIT © Mayank Sardhara