You're spending $200+/month on GPT-4, Claude, and Gemini. But you have no idea where it's going.
$ at stats
┌─────────────────┬──────────┐
│ Metric │ Value │
├─────────────────┼──────────┤
│ Total Requests │ 127 │
│ Total Tokens │ 3.2M │
│ Total Cost │ $24.5670 │
└─────────────────┴──────────┘
┌──────────┬──────────┬─────────┬──────────┬────────────┐
│ Provider │ Requests │ Tokens │ Cost │ % of Total │
├──────────┼──────────┼─────────┼──────────┼────────────┤
│ openai │ 85 │ 2.1M │ $18.2340 │ 74.2% │
│ anthropic│ 32 │ 890K │ $5.1230 │ 20.9% │
│ google │ 10 │ 210K │ $1.2100 │ 4.9% │
└──────────┴──────────┴─────────┴──────────┴────────────┘
- Quick Start
- Features
- CLI Commands
- Automatic Tracking
- Programmatic API
- Supported Providers & Models
- Architecture
- Development
- Contributing
- License
npm install -g aitoken-cli
# Track usage
at add -p openai -m gpt-4o -i 1500 -o 800
# View stats
at stats| Feature | Description |
|---|---|
| Automatic Tracking | Built-in wrappers, middleware, and SDK extensions |
| Multi-Provider | OpenAI, Anthropic, Google, Azure, Cohere |
| Automatic Costs | Up-to-date pricing for all 42 models |
| Beautiful Stats | Usage by provider, model, and time period |
| Local Storage | All data in SQLite — nothing leaves your machine |
| JSON Export | Pipe data to other tools |
| Programmatic API | Use in your code without CLI calls |
at add -p openai -m gpt-4o -i 1500 -o 800
at add -p anthropic -m claude-3.5-sonnet -i 2000 -o 1200 -n "Code review session"| Flag | Description |
|---|---|
-p, --provider |
Provider (openai, anthropic, google, azure, cohere) |
-m, --model |
Model name |
-i, --input |
Input/prompt tokens |
-o, --output |
Output/completion tokens |
-n, --notes |
Optional notes |
at list # Last 20 entries
at list -p openai # Filter by provider
at list --json # Export as JSONat stats # Overall stats
at stats -d 7 # Last 7 days
at stats -p anthropic # Specific providerat today
at today --jsonat models # All models
at models -p openai # Filter by providerat clear --yes # Clear all
at clear -p openai --yes # Clear by provider
at clear --before 2026-01-01 --yes # Clear before dateThree integration methods — pick the one that fits your workflow:
Method 1: Wrapper Functions (Easiest)
import { trackedGPT, trackedClaude } from 'aitoken-cli/wrappers';
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const response = await trackedGPT(openai, {
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }]
// Automatically tracked!
});Method 2: Middleware Pattern (Zero Code Changes)
import { createTrackedClient } from 'aitoken-cli/middleware';
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const trackedOpenAI = createTrackedClient(openai, {
provider: 'openai',
model: 'gpt-4o'
});
// Use exactly like normal — tracking is automatic
const response = await trackedOpenAI.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }]
});Method 3: SDK Extensions (Drop-in Replacement)
import { TrackedOpenAI } from 'aitoken-cli/extensions';
// Change the import — everything else stays the same
const openai = new TrackedOpenAI({
apiKey: process.env.OPENAI_API_KEY
});
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }]
});
// Automatically tracked!See EXAMPLES.md for 12 complete examples including Express.js, Next.js, and chatbot integrations.
import { addUsage, getUsage, getStats, calculateCost } from 'aitoken-cli';
const cost = calculateCost('openai', 'gpt-4o', 1500, 800);
// $0.0195
addUsage({
provider: 'openai',
model: 'gpt-4o',
promptTokens: 1500,
completionTokens: 800,
totalTokens: 2300,
cost,
timestamp: new Date().toISOString(),
notes: 'My API call',
});
const stats = getStats({ provider: 'openai' });
console.log(`Total: $${stats.totalCost.toFixed(2)}`);| Provider | Models | Highlights |
|---|---|---|
| OpenAI | 16 | GPT-5.2, GPT-4.1, GPT-4o, o4-mini, o1 |
| Anthropic | 14 | Claude Sonnet 4.5, Claude Opus 4.5, Claude 3.5 |
| 5 | Gemini 1.5 Pro, Gemini 1.5 Flash | |
| Azure OpenAI | 3 | GPT-4, GPT-4-32K, GPT-3.5 Turbo |
| Cohere | 4 | Command R+, Command R, Command |
┌─────────────────────────────────────────┐
│ aitoken-cli │
├───────────────┬─────────────────────────┤
│ CLI Layer │ Programmatic API │
│ (Commander) │ (addUsage, getStats) │
├───────────────┴─────────────────────────┤
│ Cost Calculator │
│ (42 models, auto-updated pricing) │
├─────────────────────────────────────────┤
│ SQLite Database │
│ ~/.token-tracker/usage.db │
└─────────────────────────────────────────┘
All data stays on your machine. Nothing is sent anywhere.
git clone https://github.com/brian-mwirigi/aitoken-cli.git
cd aitoken-cli
npm install
npm run build
npm link
at statsContributions welcome! Please open an issue or submit a PR.