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

@nullspend/cost-engine

v0.2.0

Published

Model pricing catalog and cost calculation engine for OpenAI, Anthropic, and Google AI

Readme

@nullspend/cost-engine

Model pricing catalog and cost calculation engine for OpenAI, Anthropic, and Google AI.

Supported Models (56 total)

  • OpenAI (26): gpt-5.4, gpt-5.4-mini, gpt-5.4-nano, gpt-5.4-pro, gpt-5.2-pro, gpt-5-pro, gpt-5.2, gpt-5.1, gpt-5, gpt-5-mini, gpt-5-nano, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-4o, gpt-4o-mini, o4-mini, o3, o3-mini, o3-pro, o1, o1-pro, o1-mini, o3-deep-research, o4-mini-deep-research, computer-use-preview
  • Anthropic (22): claude-sonnet-4-6, claude-opus-4-6, claude-sonnet-4-5, claude-opus-4-5, claude-opus-4-1, claude-opus-4, claude-sonnet-4, claude-haiku-4-5, claude-haiku-3.5, claude-haiku-3, claude-opus-4-0, claude-sonnet-4-0 (plus 10 dated variants)
  • Google (8): gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-2.0-flash, gemini-2.0-flash-lite, gemini-3-flash-preview, gemini-3.1-pro-preview, gemini-3.1-flash-lite-preview

Install

npm install @nullspend/cost-engine

Quick Start

import { getModelPricing, costComponent, isKnownModel } from "@nullspend/cost-engine";

// Check if a model is in the catalog
isKnownModel("openai", "gpt-4o"); // true

// Get pricing rates ($/million tokens)
const pricing = getModelPricing("openai", "gpt-4o");
if (pricing) {
  // { inputPerMTok: 2.50, cachedInputPerMTok: 1.25, outputPerMTok: 10.00 }

  // Calculate cost for a token component (returns unrounded microdollars)
  const inputCost = costComponent(1500, pricing.inputPerMTok);
  const outputCost = costComponent(500, pricing.outputPerMTok);
  const totalMicrodollars = Math.round(inputCost + outputCost);
}

API

getModelPricing(provider: string, model: string): ModelPricing | null

Returns pricing rates for a model, or null if not in the catalog.

getModelPricing("anthropic", "claude-sonnet-4-6");
// { inputPerMTok: 3.0, cachedInputPerMTok: 0.3, outputPerMTok: 15.0,
//   cacheWrite5mPerMTok: 3.75, cacheWrite1hPerMTok: 6.0 }

isKnownModel(provider: string, model: string): boolean

Returns true if the model exists in the pricing catalog.

costComponent(tokens: number, ratePerMTok: number): number

Calculates cost in microdollars (unrounded float) for a given token count and rate. Sum all components and call Math.round() once at the end to avoid accumulation drift.

getAllPricing(): Readonly<Record<string, ModelPricing>>

Returns the complete frozen pricing catalog keyed by "provider/model".

Types

type Provider = "openai" | "anthropic" | "google";

interface ModelPricing {
  inputPerMTok: number;
  cachedInputPerMTok: number;
  outputPerMTok: number;
  cacheWrite5mPerMTok?: number;   // Anthropic only — 5-min cache write (1.25x input)
  cacheWrite1hPerMTok?: number;   // Anthropic only — 1-hour cache write (2.0x input)
}

interface CostEvent {
  requestId: string;
  provider: Provider;
  model: string;
  inputTokens: number;
  outputTokens: number;
  cachedInputTokens: number;
  reasoningTokens: number;
  costMicrodollars: number;
  durationMs?: number;
}

Cost Units

All costs are in microdollars (1 microdollar = $0.000001, so $1 = 1,000,000 microdollars). Rates in ModelPricing are $/million tokens. This avoids floating-point precision issues common with fractional dollar amounts.

License

Apache-2.0