DEV Community

Henry Godnick
Henry Godnick

Posted on

Stop Guessing Your API Costs: Track LLM Token Usage in Real Time

If you're building anything with LLMs in 2026, you already know the pain: API costs creep up silently, and by the time you check your dashboard, you've burned through way more tokens than expected.

The Problem

Most developers interact with multiple LLM providers throughout the day — OpenAI, Anthropic, Google, maybe a local model or two. Each has its own pricing, its own dashboard, its own way of counting tokens. Keeping track means juggling browser tabs and doing mental math.

Even worse, you often don't realize a prompt is expensive until after you've sent it. That 4,000-token system prompt you copy-paste into every request? It adds up fast when you're iterating.

What Actually Helps

The approach that's saved me the most money is dead simple: watch your token usage in real time, not after the fact.

I started using TokenBar — it's a macOS menu bar app that shows live token counts as you work. No context switching, no dashboards to check later. Just a persistent counter sitting in your menu bar.

What surprised me was how much my behavior changed once the numbers were always visible. I started:

  • Writing tighter prompts (cut my average by ~30%)
  • Noticing when a conversation context was getting bloated
  • Catching runaway loops in my agent code before they drained my balance

Quick Tips for Reducing Token Spend

  1. Trim your system prompts. Most are 2-3x longer than they need to be. Every token counts when it's prepended to every request.

  2. Use streaming wisely. Streaming doesn't save tokens, but it helps you cancel early if the response is heading in the wrong direction.

  3. Cache aggressively. If you're sending the same context repeatedly, cache the response. Anthropic's prompt caching is great for this.

  4. Monitor in real time. Dashboards are for retrospectives. You need something that shows you the cost while you're spending it.

The Bottom Line

LLM costs aren't going to zero anytime soon, despite what the hype says. The developers who keep their API bills under control are the ones who treat token usage like any other metric — something you monitor continuously, not something you check once a month.

TokenBar is $5 lifetime at tokenbar.site if you want to try the real-time monitoring approach. But whatever tool you use, the principle is the same: make the invisible visible.

What's your approach to managing LLM costs? Drop your tips in the comments 👇

Top comments (0)