DEV Community

Henry Godnick
Henry Godnick

Posted on

I Tracked Every Token I Spent on LLM APIs for a Month — Here's What I Learned

If you're building with LLM APIs — OpenAI, Anthropic, Gemini, whatever — you're probably hemorrhaging tokens without realizing it.

I spent a month obsessively tracking every single token across all my projects, and the results were genuinely surprising.

The Setup

I work on multiple projects that hit various LLM endpoints throughout the day. Code generation, chat interfaces, data processing pipelines — the usual indie dev stack in 2026.

The problem? I had no idea where my money was actually going. My OpenAI bill would spike and I'd just... shrug.

What I Found

System prompts are the silent killer. One of my apps was sending a 4,000-token system prompt on every single request. That's tokens you pay for but your user never sees. I trimmed it to 800 tokens with zero quality loss.

Streaming doesn't save you money. I know, obvious in hindsight. But I had this mental model that streaming was somehow "cheaper" because it felt faster. Nope. Same tokens, same cost.

Context window stuffing is real. I was shoving entire conversation histories into every request. Implementing a simple sliding window cut my costs by 40%.

The Tool That Changed Everything

I started using TokenBar — it's a macOS menu bar app that gives you real-time token counts. Dead simple: it just sits in your menu bar and shows you exactly what you're spending as you work. $5 lifetime, which paid for itself in the first hour when I caught a runaway loop burning through GPT-4 tokens.

The key insight wasn't any single optimization. It was visibility. Once you can actually see your token usage in real time, you naturally start writing tighter prompts and smarter context management.

Quick Wins

  1. Audit your system prompts. Cut them by 50%. Seriously.
  2. Implement token budgets per request. Set max_tokens aggressively.
  3. Cache repeated completions. If you're asking the same question twice, that's pure waste.
  4. Monitor in real time. You can't optimize what you can't see.

The LLM cost problem isn't going away — models are getting more capable but context windows keep growing, and bigger context means bigger bills. Get ahead of it now.


What's your token management strategy? Drop it in the comments — I'm always looking for new tricks.

Top comments (0)