I checked my OpenAI billing last month. $217. I had no idea where it went.
The solution: I built aitoken-cli. Now I track every cent.
The result: Reduced spending to $89/month. 59% savings.
The Hidden Cost of AI Development
If you're a developer in 2026, you're using AI APIs. GPT-4, Claude, Gemini they're essential tools.
The costs creep up silently.
My Wake-Up Call
December 2025:
- Week 1: $12 (seems fine)
- Week 2: $28 (okay, working on a project)
- Week 3: $51 (wait, what?)
- Week 4: $126 (WTF?!)
Total: $217
I was a broke CS student burning $217/month on AI. Something had to change.
Why Existing Solutions Failed Me
You'd think tracking API costs is solved, right? Wrong.
OpenAI Dashboard
- Shows totals only
- No breakdown by task
- No comparison across providers
- Have to log in every time
Spreadsheets
- Manual entry (I forgot constantly)
- No automatic cost calculation
- Boring, never kept it updated
Existing npm packages
- Too complex (need servers, databases)
- Privacy concerns (send data to cloud)
- Not comprehensive (OpenAI only)
The gap: I needed something local, fast, and comprehensive.
Building aitoken-cli
Friday night, 9 PM: Just got my $217 bill. Angry.
Friday night, 11 PM: Sketched the design.
Saturday, 3 AM: First version working. Tracking OpenAI only.
Saturday, 9 AM: Added Anthropic, Google, Azure, Cohere.
Saturday, 2 PM: Published to npm.
Total time: 6 hours.
How It Works
Track Usage in Seconds
# Track a GPT-4 call
at add -p openai -m gpt-4o -i 1500 -o 800
# Output: ✓ Added usage #47 - openai/gpt-4o - $0.0118
View Your Stats
at stats
# Output:
# Total Usage: $34.56 (245,890 tokens)
#
# By Provider:
# OpenAI: $21.34 (150,000 tokens)
# Anthropic: $11.22 (85,000 tokens)
# Google: $2.00 (10,890 tokens)
Today's Spending
at today
# Output:
# Today's Usage: $4.23 (15,670 tokens)
#
# Latest entries:
# 10:15 AM - gpt-4o - $1.52 (5,000 tokens)
# 11:30 AM - claude-3.5 - $2.71 (10,670 tokens)
Integrate with Your Code
// After an OpenAI call
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages
});
// Track it
const { prompt_tokens, completion_tokens } = response.usage;
exec(`at add -p openai -m gpt-4o -i ${prompt_tokens} -o ${completion_tokens}`);
The Impact: Real Savings
Before aitoken-cli (December 2025):
- Monthly cost: $217
- Awareness: Zero
- Optimization: None
After aitoken-cli (January 2026):
- Monthly cost: $89
- Awareness: 100%
- Optimization: Strategic model switching
Savings: $128/month (59% reduction)
How I Optimized My AI Spending
Discovery 1: GPT-4 for Everything Was Wasteful
Before: Used GPT-4 for simple tasks like string formatting
Fix: Use GPT-3.5 Turbo for simple tasks
Savings: $40/month
Discovery 2: Long Prompts Every Time
Before: Sent full system prompts with every request
Fix: Cache system prompts, send only deltas
Savings: $30/month
Discovery 3: Claude is Often Better AND Cheaper
Before: Default to GPT-4 for everything
Fix: Use Claude 3.5 Sonnet for coding tasks
Savings: $35/month
Discovery 4: Redundant API Calls
Before: Making duplicate calls without noticing
Fix: Added request deduplication
Savings: $23/month
None of this was possible without tracking.
Technical Details
Tech Stack
- TypeScript - Type safety for pricing data
- Commander.js - CLI framework
- SQLite (better-sqlite3) - Local database
- Chalk - Pretty terminal output
Database Schema
CREATE TABLE usage (
id INTEGER PRIMARY KEY,
provider TEXT NOT NULL,
model TEXT NOT NULL,
prompt_tokens INTEGER NOT NULL,
completion_tokens INTEGER NOT NULL,
total_tokens INTEGER NOT NULL,
cost REAL NOT NULL,
timestamp TEXT NOT NULL,
notes TEXT
);
Simple. Effective. Local.
Privacy: Why Local Matters
aitoken-cli stores everything in ~/.aitoken/usage.db.
No cloud. No API. No tracking.
Why?
- Your usage patterns are private - Nobody knows what you're building
- Works offline - No internet? Still tracks
- Fast - No network latency
- Free forever - No subscription costs
- You own your data - Export anytime
Installation
npm install -g aitoken-cli
Quick Start
# Track your first API call
at add -p openai -m gpt-4o -i 1000 -o 500
# View your stats
at stats
# See today's usage
at today
# List all providers and models
at models
What's Next
Coming soon:
- Budget alerts (warn when you hit $X/month)
- Model recommendations (suggest cheaper alternatives)
- CSV export for accounting
- Team usage tracking
Try It Today
Challenge
Track your AI usage for one week. I bet you'll be surprised by what you find.
npm install -g aitoken-cli
Then tweet your results with #aitokencli – I'll retweet the most interesting findings.
Resources
Other Tools I've Built
- runbook-cli - Remember project commands
- codesession-cli - Track coding sessions
Building in public: Follow my journey @brian_mwirigi
Github: github.com/brian-mwirigi
Blog: brianmunene.me/blog
INFO: If you find any bugs or issues please feel free to reach out
`
Top comments (1)
Hell of a debut huh?