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

token-costs

v3.4.0

Published

Daily LLM token pricing data with automatic updates

Readme

Token Costs

Daily-updated LLM pricing data for OpenAI, Anthropic, Google, and OpenRouter.

What Is This?

An npm package and JSON API that gives you up-to-date token pricing for major LLM providers. Stop hardcoding prices or manually checking pricing pages.

import { CostClient } from 'token-costs';

// Create a client (fetches from remote API)
const client = new CostClient();

// Get pricing for a model
const result = await client.getModelPricing('openai', 'gpt-4o');
console.log(`Input: $${result.pricing.input}/M tokens`);
console.log(`Output: $${result.pricing.output}/M tokens`);

// Calculate cost for an API call
const cost = await client.calculateCost('anthropic', 'claude-sonnet-4', {
  inputTokens: 1500,
  outputTokens: 800,
});
console.log(`Total cost: $${cost.totalCost.toFixed(6)}`);

// OpenRouter models use provider/model format
const orPricing = await client.getModelPricing('openrouter', 'anthropic/claude-3.5-sonnet');

Or fetch directly without dependencies:

const data = await fetch('https://mikkotikkanen.github.io/token-costs/api/v1/openai.json')
  .then(r => r.json());

Features

  • Daily updates - Crawled automatically at 00:01 UTC
  • 4 providers - OpenAI, Anthropic, Google, OpenRouter
  • Custom providers - Add your own models or override pricing
  • Offline mode - Work without network access using custom data
  • Zero dependencies - npm package has no runtime dependencies
  • TypeScript - Full type definitions included
  • Caching - Fetches once per day, caches automatically
  • Stale detection - Know when data might be outdated

Installation

npm install token-costs

Custom Providers & Offline Mode

Add custom models or use entirely custom pricing data:

// Add custom models alongside remote data
const client = new CostClient({
  customProviders: {
    'my-company': {
      'internal-llm': { input: 0.50, output: 1.00 }
    },
    'openai': {
      'gpt-4-custom': { input: 25, output: 50 } // Override/add to openai
    }
  }
});

// Offline mode - no remote fetching
const offlineClient = new CostClient({
  offline: true,
  customProviders: {
    'openai': {
      'gpt-4o': { input: 2.5, output: 10 }
    }
  }
});

Documentation

Full usage guide, API reference, and data formats: mikkotikkanen.github.io/token-costs

What's Included

token-costs/
├── CostClient        # Main client class with caching
└── TypeScript types     # Full type definitions

API Endpoints (JSON):

  • api/v1/openai.json
  • api/v1/anthropic.json
  • api/v1/google.json
  • api/v1/openrouter/{provider}.json - Per-provider files (anthropic, openai, google, deepseek, etc.)

Contributing

Found incorrect pricing? Want to add a provider? Contributions welcome!

git clone https://github.com/mikkotikkanen/token-costs
cd token-costs
npm install
npm run build
npm test

See AGENTS.md for development details.

For LLM Providers

We'd prefer not to scrape. Consider publishing /llm_prices.json on your website - a simple standard format that tools can fetch directly. See the full proposal on the documentation site.

License

MIT