Open Source · 5 Providers · Zero Config

Know exactly what your AI calls cost.

Real-time token cost tracking across Claude, GPT, Gemini, Llama, and more. Drop in two lines of code. Budget alerts, live callbacks, CSV export.

$npm install ai-token-cost-meter
5+Providers
25+Models
MITLicense
node index.js
1
Features

Everything you need to track AI spend

From budget guardrails to per-call callbacks, ai-token-cost-meter gives you full visibility into what your AI usage actually costs.

Multi-Provider

Track costs across Anthropic, OpenAI, Google, Meta, and Mistral from a single unified API.

Precise Pricing

Pre-loaded with current pricing for 25+ models. Costs calculated per million tokens, automatically.

Budget Alerts

Set a spending cap in USD. Get instant warnings when your session crosses the threshold.

Live Callbacks

Register onTrack hooks that fire on every API call — stream costs to a dashboard, Slack, or anywhere.

Export to JSON / CSV

Dump full session history with one call. Drop into spreadsheets, databases, or analytics pipelines.

Zero Config

Works out of the box. No API keys, no setup, no config files. Two lines to start tracking.

Supported Providers

One package, every major provider

Built-in pricing for 25+ models across 5 providers. Add any custom model with your own per-million token rates.

A
Anthropic
4+ models
claude-opus-4-7
claude-sonnet-4-6
claude-haiku-4-5
Claude 3.x series
O
OpenAI
8 models
gpt-4o
gpt-4o-mini
gpt-4-turbo
o1
o1-mini
o3-mini
G
Google
4 models
gemini-1.5-pro
gemini-1.5-flash
gemini-2.0-flash
gemini-2.0-flash-lite
M
Meta
2 models
llama-3.3-70b
llama-3.1-8b
Mi
Mistral
3 models
mistral-large
mistral-small
mixtral-8x7b
+
Custom Model

Register any model with your own pricing in one line.

meter.addModel(
  'my-model',
  5.00, 20.00,
  'MyProvider'
);
Quick Start

Up and running in 60 seconds

No configuration files, no API keys, no boilerplate. Install, import, track.

01

Install the package

Add ai-token-cost-meter to your project with npm, yarn, or pnpm.

npm install ai-token-cost-meter
02

Track your API calls

Call meter.track() after each AI API call, or use trackFromResponse() to read counts directly from the response object.

const { meter } = require('ai-token-cost-meter');

// Option A: Manual tracking
meter.track('claude-sonnet-4-6', 1500, 800);

// Option B: Auto-parse from SDK response
const response = await anthropic.messages.create({ ... });
meter.trackFromResponse('claude-sonnet-4-6', response);
03

Report and export

Print a formatted table to the console, export to JSON or CSV, or access raw session data.

// Print the cost table
meter.report();

// Export to CSV
const csv = meter.export('csv');
require('fs').writeFileSync('ai-costs.csv', csv);

// Get total cost
console.log(`Session cost: $${meter.totalCost().toFixed(4)}`);
API Reference

Simple, predictable API

One global meter instance. Click any method to see the signature, description, and a working code example.

Need isolated sessions? Use new Tracker()

The default meter is a shared singleton. For per-user or per-request isolation, create independent Tracker instances.

multi-session.js
const { Tracker } = require('ai-token-cost-meter');

const userA = new Tracker();
const userB = new Tracker();

userA.track('gpt-4o', 1000, 500);
userB.track('claude-sonnet-4-6', 2000, 800);

console.log(userA.totalCost()); // only userA's cost
console.log(userB.totalCost()); // only userB's cost
Free · Open Source · MIT

Start tracking your AI spend today.

Two lines of code. No config. No account. Just real numbers.

$npm install ai-token-cost-meter
View on npm