DEV Community

Henry Godnick
Henry Godnick

Posted on

Stop Guessing Your LLM Costs: How I Track Every Token in Real Time

If you're building with LLMs in 2026, you already know the pain: you're deep in a coding session, firing off prompts to Claude, GPT, or Gemini, and at the end of the month your API bill is... a surprise.

I got tired of the guessing game. Here's what I learned about tracking token usage in real time, and the setup I landed on.

The Problem

Most LLM providers give you usage dashboards, but they're delayed. OpenAI's dashboard updates every few hours. Anthropic's is similar. If you're iterating fast — testing prompts, building agents, running evals — you have zero visibility into what you're spending right now.

For indie devs and small teams, this matters. A runaway loop or a badly constructed prompt can burn through $50 before you even notice.

What Actually Helps

1. Track at the request level, not the billing level.

Every API response includes token counts in the response headers or body. Parse them. Log them. If you're using Python, a simple wrapper around your API calls can accumulate input/output tokens per session.

2. Set up real-time visibility.

I wanted something always visible — not buried in a tab I'd forget about. I ended up using TokenBar, a Mac menu bar app that shows your running token count and estimated cost in real time. It sits right next to my clock. One glance and I know exactly where I stand. It's $5 lifetime which is basically nothing compared to what it saves you in surprise bills.

3. Set budget alerts early.

Most providers let you set spending limits. Do it. Set them lower than you think you need. It's much easier to bump a limit up than to explain to yourself why you spent $200 on a weekend project.

The Bigger Picture

As LLMs get cheaper per token but we use them more, total spend actually goes up for most developers. The only defense is visibility. Know what you're spending, when you're spending it, and on what.

If you've got your own token tracking setup, I'd love to hear about it in the comments. What tools or scripts are you using?

Top comments (0)