Real-time token cost tracking across Claude, GPT, Gemini, Llama, and more. Drop in two lines of code. Budget alerts, live callbacks, CSV export.
From budget guardrails to per-call callbacks, ai-token-cost-meter gives you full visibility into what your AI usage actually costs.
Track costs across Anthropic, OpenAI, Google, Meta, and Mistral from a single unified API.
Pre-loaded with current pricing for 25+ models. Costs calculated per million tokens, automatically.
Set a spending cap in USD. Get instant warnings when your session crosses the threshold.
Register onTrack hooks that fire on every API call — stream costs to a dashboard, Slack, or anywhere.
Dump full session history with one call. Drop into spreadsheets, databases, or analytics pipelines.
Works out of the box. No API keys, no setup, no config files. Two lines to start tracking.
Built-in pricing for 25+ models across 5 providers. Add any custom model with your own per-million token rates.
Register any model with your own pricing in one line.
meter.addModel(
'my-model',
5.00, 20.00,
'MyProvider'
);No configuration files, no API keys, no boilerplate. Install, import, track.
Add ai-token-cost-meter to your project with npm, yarn, or pnpm.
npm install ai-token-cost-meterCall 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);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)}`);One global meter instance. Click any method to see the signature, description, and a working code example.
new Tracker()The default meter is a shared singleton. For per-user or per-request isolation, create independent Tracker instances.
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 costTwo lines of code. No config. No account. Just real numbers.