Vibe Coding Forem

Brian Munene Mwirigi
Brian Munene Mwirigi

Posted on

I Got Tired of Burning Money on AI APIS - Built a CLI Tool to Fix It

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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}`);
Enter fullscreen mode Exit fullscreen mode

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
);
Enter fullscreen mode Exit fullscreen mode

Simple. Effective. Local.

Privacy: Why Local Matters

aitoken-cli stores everything in ~/.aitoken/usage.db.

No cloud. No API. No tracking.

Why?

  1. Your usage patterns are private - Nobody knows what you're building
  2. Works offline - No internet? Still tracks
  3. Fast - No network latency
  4. Free forever - No subscription costs
  5. You own your data - Export anytime

Installation

npm install -g aitoken-cli
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then tweet your results with #aitokencli – I'll retweet the most interesting findings.

Resources

Other Tools I've Built


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)

Collapse
 
brianmwirigi_61 profile image
Brian Munene Mwirigi

Hell of a debut huh?