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

@ferrow/llm-cost-estimator

v1.0.0

Published

LLM usage cost accounting — you supply the price table, this accumulates per-model/label cost breakdowns, projections, budget alerts, and CSV/JSON export. Zero runtime dependencies.

Readme

llm-cost-estimator

CI

LLM usage cost accounting — you supply the price table, this tracks per-model/label cost breakdowns, projections, budget alerts, and CSV/JSON export. Zero runtime dependencies, strict TypeScript.

Prices change too fast to hardcode. This library ships no built-in model prices. You pass your own price table at construction time and keep it current from your provider's pricing page.

Quickstart

import { CostTracker } from "llm-cost-estimator";

// ILLUSTRATIVE prices only — check your provider's current pricing page.
const prices = {
  "example-large": { inputPer1M: 3.0, outputPer1M: 15.0, cacheReadPer1M: 0.3 },
  "example-small": { inputPer1M: 0.25, outputPer1M: 1.25 },
};

const tracker = new CostTracker(prices);

tracker.onBudgetThreshold(10, ({ totalCost, threshold }) => {
  console.log(`Crossed $${threshold}: total is now $${totalCost.toFixed(2)}`);
});

tracker.record({ model: "example-large", label: "chat", inputTokens: 1200, outputTokens: 400 });

tracker.breakdown();
// => [{ model, label, requestCount, totalInputTokens, totalOutputTokens, totalCacheReadTokens, totalCost, avgCostPerRequest }]

tracker.project(500); // requests/day
// => { avgCostPerRequest, requestsPerDay, projectedDailyCost, projectedMonthlyCost }

tracker.toCSV();  // CSV ledger
tracker.toJSON(); // JSON ledger (RecordedEntry[])

API

new CostTracker(prices: PriceTable)

PriceTable is Record<string, ModelPricing> where ModelPricing is { inputPer1M: number; outputPer1M: number; cacheReadPer1M?: number }.

computeCost(usage): number

Compute the cost of one UsageRecord without recording it.

record(usage): RecordedEntry

Records usage and returns the entry with its computed cost and timestamp (defaults to Date.now()). Checks all registered budget alerts after recording.

UsageRecord: { model, label?, inputTokens, outputTokens, cacheReadTokens?, timestamp? }

totalCost(): number / getEntries(): RecordedEntry[]

Running total and the full ledger, in insertion order.

breakdown(): BreakdownRow[]

Per model+label rows (unlabeled records group under "(unlabeled)"), sorted by totalCost descending: request count, token totals, total cost, average cost per request.

project(requestsPerDay): Projection

Projects avgCostPerRequest (computed from all recorded entries so far) forward to projectedDailyCost and projectedMonthlyCost (× 30).

onBudgetThreshold(threshold, callback): void

Registers a callback that fires once the first time total cost crosses threshold. Register multiple thresholds for a staged alert ladder.

toCSV(): string / toJSON(): RecordedEntry[]

Export the full ledger.

Limits

  • No built-in prices. The PriceTable you provide is the sole source of truth; this library has no opinion on what any model costs and does not fetch prices from anywhere.
  • project() extrapolates linearly from the observed average cost per request — it does not account for prompt-length drift, discount tiers, or caching hit-rate changes over time.
  • onBudgetThreshold fires once per threshold for the lifetime of the tracker instance; it does not re-fire if cost later drops below and crosses again.

Part of the ferrow-toolkit collection · Sponsored by Ferrow