{"slug": "i-built-a-local-first-cli-to-track-what-i-m-actually-spending-on-ai-apis", "title": "I built a local-first CLI to track what I'm actually spending on AI APIs", "summary": "A developer built AICostTracker, a local-first CLI tool that logs API calls to OpenAI, Anthropic, Google, and Ollama models and provides a cost breakdown by project and model. The tool stores data in a local JSONL file, avoiding the need for a SaaS dashboard.", "body_md": "Every month I got surprised by my OpenAI bill.\n\nNot by a lot — but enough that I'd open the usage dashboard, squint at a chart, try to remember which project burned all those tokens, and give up. The dashboard shows totals. It doesn't help you understand *which project* cost the most, *which model* was doing the work, or whether that refactoring session with GPT-4 was actually cheaper than Claude.\n\nSo I built [AICostTracker](https://github.com/Ozperium/aicost-tracker) — a local CLI that logs API calls and shows a cost breakdown by project and model.\n\nLog a call after you make it:\n\n```\naicost log myapp gpt-4o 1500 800 \"generated README\"\naicost log agentspec claude-3.5-sonnet 2000 1200 \"test run\"\n```\n\nThen see what you spent:\n\n```\naicost summary\n```\n\nOutput:\n\n```\n  AI Cost Tracker — Summary\n  ══════════════════════════════════════════════════\n  Total entries:    2\n  Total cost:       $0.0358\n  Input tokens:     3,500\n  Output tokens:    2,000\n\n  By Project:\n  ──────────────────────────────────────────────────\n  myapp                $    0.0118  1 calls\n  agentspec            $    0.0240  1 calls\n\n  By Model:\n  ──────────────────────────────────────────────────\n  gpt-4o               $    0.0118  1 calls\n  claude-3.5-sonnet    $    0.0240  1 calls\n```\n\nI didn't want another SaaS with an account and a dashboard. The data lives in `~/.aicost/usage.jsonl`\n\n— one JSON line per call, greppable, portable, yours.\n\nPricing is baked in for OpenAI (gpt-4o, o1, gpt-4-turbo, gpt-3.5), Anthropic (claude-3.5-sonnet, claude-3-opus, haiku), Google (gemini-1.5), and local/Ollama models (cost: $0).\n\n```\nnpm install -g @ozperium/aicost-tracker\naicost log myproject gpt-4o 1000 500 \"first entry\"\naicost summary\n```\n\nThe obvious next step is automatic logging — a wrapper that intercepts API calls so you don't have to log manually. For now, manual logging is good enough to surface the patterns that matter.\n\nIf you use multiple AI APIs and want to know where your money's actually going, give it a try.\n\nGitHub: [https://github.com/Ozperium/aicost-tracker](https://github.com/Ozperium/aicost-tracker)\n\n*Also in the stack: AgentSpec for testing AI agent behavior, and quota for tracking rate limits before they stop you.*", "url": "https://wpnews.pro/news/i-built-a-local-first-cli-to-track-what-i-m-actually-spending-on-ai-apis", "canonical_source": "https://dev.to/pawfromoz/i-built-a-local-first-cli-to-track-what-im-actually-spending-on-ai-apis-2ajo", "published_at": "2026-07-23 22:23:17+00:00", "updated_at": "2026-07-23 23:02:01.285465+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-infrastructure"], "entities": ["OpenAI", "Anthropic", "Google", "Ollama", "AICostTracker", "AgentSpec"], "alternates": {"html": "https://wpnews.pro/news/i-built-a-local-first-cli-to-track-what-i-m-actually-spending-on-ai-apis", "markdown": "https://wpnews.pro/news/i-built-a-local-first-cli-to-track-what-i-m-actually-spending-on-ai-apis.md", "text": "https://wpnews.pro/news/i-built-a-local-first-cli-to-track-what-i-m-actually-spending-on-ai-apis.txt", "jsonld": "https://wpnews.pro/news/i-built-a-local-first-cli-to-track-what-i-m-actually-spending-on-ai-apis.jsonld"}}