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

ai-cost-tracker-pro

v1.2.1

Published

Automatically track token usage and cost for AI API requests (OpenAI, Anthropic, Gemini).

Readme

ai-cost-tracker-pro 🚀💸

Stop burning money on AI APIs without knowing it.

ai-cost-tracker-pro automatically tracks token usage and cost across OpenAI, Anthropic, and Gemini — with zero setup.

Powered by Gemini 2.0

⚡ Know exactly where your AI budget is going in real time.


⚡ What You See Instantly

After running:

npx ai-cost-tracker dev

You get:

Real-time cost updates
Token usage per request
Most expensive API calls
Suggestions to reduce cost

Example Insight:

Total Cost Today: $3.42
Most Expensive Model: GPT-4
Suggestion: Switch 60% traffic → GPT-4o-miniSave ~$1.10/day

👉 This is the simplest way to take control of your AI infrastructure.


import { monitorAI } from "ai-cost-tracker-pro"

// Zero-Config: Just add this at any start of your app
await monitorAI() 

📦 Key Features

  • Auto-Tracking: Instantly patches OpenAI, Anthropic, and Gemini (2.0+).
  • Zero Configuration: Detects API keys from your environment automatically.
  • Local Dashboard: Visual insights into your spend without leaving your machine.
  • Pro Ready: Optional cloud sync for team-wide analytics and alerts.

🎯 Use Cases

  • SaaS apps using OpenAI / Claude
  • AI agents & automation tools
  • Chatbots & copilots
  • Internal tools with AI APIs
  • Startups tracking burn rate

🔥 If you're paying for AI APIs — you need this.


🤔 Without vs With ai-cost-tracker

| Without | With | | :--- | :--- | | ❌ No idea where money is going | ✅ Real-time cost tracking | | ❌ Surprise bills at end of month | ✅ Smart suggestions to save $ | | ❌ No optimization strategy | ✅ Full visibility across models |


Manual Integration (Optional)

If you prefer manual control, use our lightweight wrappers:

OpenAI

import { trackOpenAI } from "ai-cost-tracker-pro"
import OpenAI from "openai"

const client = trackOpenAI(new OpenAI())

Anthropic

import { trackAnthropic } from "ai-cost-tracker-pro"
import { Anthropic } from "@anthropic-ai/sdk"

const client = trackAnthropic(new Anthropic())

Google Gemini (2.0+)

Works with both the standard and the newest Gemini SDKs:

New SDK (@google/genai):

import { trackGenAI } from "ai-cost-tracker-pro"
import { GoogleGenAI } from "@google/genai"

const client = trackGenAI(new GoogleGenAI({ apiKey: "YOUR_KEY" }))

Standard SDK (@google/generative-ai):

import { trackGemini } from "ai-cost-tracker-pro"
import { GoogleGenerativeAI } from "@google/generative-ai"

const genAI = new GoogleGenerativeAI("YOUR_KEY")
const model = trackGemini(genAI.getGenerativeModel({ model: "gemini-1.5-flash" }))

📊 Powerful Local Dashboard

Visualize your AI spending instantly. The dashboard reads from the .ai-usage.json file generated in your project root.

How to use:

  1. Generate Data: Run your AI project at least once (using monitorAI() or manual wrappers).
  2. Launch:
    npx ai-cost-tracker dev
  3. Analyze: Open the provided local URL (usually http://localhost:3000) to see:
    • Real-time Cost Charts: Watch your budget in a live timeline.
    • Model Breakdown: See which models (gpt-4, gemini-pro, etc.) are most expensive.
    • Cost Optimization: Get automatic advice on switching models to save money.

💻 CLI Reports

If you prefer the terminal, you can get quick summaries without leaving your shell:

| Command | Description | | --- | --- | | npx ai-cost-tracker report | Print a detailed usage table in your terminal. | | npx ai-cost-tracker dev | (Recommended) Launch the interactive local web dashboard. | | npx ai-cost-tracker upgrade | View Pro features and visit the Live Cloud Dashboard. |


🚀 Show Off Your Efficiency

Show your users (and investors) you care about efficiency! Run npx ai-cost-tracker-pro init-readme to add this badge to your project:

AI Cost Tracked

👉 Projects with this badge:

  • Signal cost awareness
  • Build trust with users
  • Stand out to investors

Free vs Pro Features

| Feature | Free | Pro | | --- | --- | --- | | Local Tracking | ✅ | ✅ | | CLI Reports | ✅ | ✅ | | Context-Aware (User/Team) | ✅ | ✅ | | Cloud Sync | ❌ | ✅ | | Cost Alerts | ❌ | ✅ | | Real-Time Hooks | ❌ | ✅ | | Team Analytics | ❌ | ✅ |

🚀 Why Upgrade?

If you're building anything serious with AI:

  • You NEED cost alerts before bills explode.
  • You NEED team-level visibility to track usage across developers.
  • You NEED historical tracking to spot trends and optimize.

👉 Free is for individuals
👉 Pro is for real products


Configuration (Pro)

To enable Pro features, configure the tracker with your API key:

import { configureAITracker } from "ai-cost-tracker-pro"

configureAITracker({
  apiKey: "your_pro_api_key",
  endpoint: "https://your-saas-backend.com/api/v1/usage"
})

Environment Variables (Optional)

  • OPENAI_API_KEY: Automatically used if present.
  • AI_TRACKER_API_KEY (PRO): Your SaaS API Key for cloud sync.
  • AI_TRACKER_ENDPOINT (PRO): Custom SaaS endpoint (defaults to cloud).

Real-Time Hooks (Pro)

import { onUsage } from "ai-cost-tracker-pro"

onUsage((data) => {
  console.log(`Model ${data.model} used ${data.totalTokens} tokens. Cost: $${data.cost}`)
})

🚀 Roadmap

  • [x] Zero-Config Mode
  • [x] Model Recommendations
  • [x] Local Dashboard
  • [x] SaaS Cloud Sync
  • [x] Stripe Billing
  • [x] Viral growth features
  • [ ] Mobile App (Coming Soon)

🚀 Quick Start (Testing in a new project)

Want to see it in action in under 60 seconds?

  1. Install: npm install ai-cost-tracker-pro @google/genai tsx
  2. Setup: Add your GEMINI_API_KEY to your .env.
  3. Run AI Call:
import { monitorAI, tracker } from 'ai-cost-tracker-pro';
import { GoogleGenAI } from '@google/genai';

await monitorAI();

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
await ai.models.generateContent({ 
  model: 'gemini-1.5-flash', 
  contents: [{role: 'user', parts: [{text: 'Hi!'}]}] 
});

console.log('Usage Recorded!');
  1. Launch Dashboard: npx ai-cost-tracker dev and visit http://localhost:3001.

👉 Stop guessing. Start measuring.