DEV Community

Nate Voss
Nate Voss

Posted on

3 Things I Learned Auditing My LLM App's Token Spend (And Why Your Benchmarks Are Lying)

You know that feeling when you ship an AI feature and realize your token bill is 3x what you estimated? Yeah, that was me last week.

I have this thing called Agent-Max — it's a multi-platform growth agent that runs autonomous workflows: generating content, publishing to Bluesky, Medium, Twitter, Reddit. Sounds heavy, right? Every Monday it synthesizes a week of reading, scrapes engagement metrics, decides what to post and where. Seven platforms. Infinite LLM calls if you're not paying attention.

Last Sunday I realized I had no idea what I was actually spending. I knew roughly — "somewhere between $5-20/week" — but roughly is how you end up with bill shock. So I built PromptFuel to solve the actual problem: measure what your app is doing, not what the docs say it should do.

Here's what three days of auditing my own code taught me.

1. Your bottleneck isn't the model you picked, it's the prompt you didn't trim

I assumed my biggest cost sink was the weekly reflection. Claude reads 7 days of snapshots, engagement data, content history, trend analysis, then reasons about next week's strategy. Heavy prompt, right?

Nope.

Running pf optimize on the actual prompts showed the reflection was 2,847 tokens. Not small, but fine. The real killer: the daily content pregeneration loop was calling Claude 5 times per platform, and each call had:

  • Entire engagement history (redundant. I'm fetching fresh data every run)
  • Every. Single. Previous. Post. (all 120 of them, in the context)
  • Current date, weather, trending topics (reloaded every call)

Cutting history to "last 10 posts, last 3 days of engagement" knocked 40% off. Not because I switched models. Because I stopped hallucinating I needed context I wasn't even reading.

2. Your audit will surface the dumb stuff, not the obvious stuff

Benchmarks tell you Claude costs 3¢ per 1M input tokens. Haiku costs 0.8¢. Pick the right model, do the math, move on.

Except I was calling Claude Sonnet 7 times/week on background analytics where Haiku was plenty. Not intentional. I'd copied the model from an earlier prompt and never thought about it again. One-line change, zero quality loss, $2 saved per month.

That math never shows up in a benchmark. It shows up in your actual codebase, on your actual data, running your actual job. PromptFuel's advantage isn't telling you models are expensive. It's finding the calls you forgot about and showing you the before/after side-by-side.

3. Once you see the numbers, the optimization loop becomes obvious

The first time I ran the dashboard, I thought I was done. Then Monday's weekly job ran and I watched 47 new prompts execute. Dashboard updated in real time. I saw the pattern. There's another cut.

Auditing once is useful. Auditing every week is how you stop bleeding money.


Let's walk through it

Install:

npm install -g promptfuel
Enter fullscreen mode Exit fullscreen mode

Run pf optimize on a real prompt:

pf optimize ./src/prompts/reflect.md --model claude-3-5-sonnet
Enter fullscreen mode Exit fullscreen mode

You'll see token count, cost per call, and a readability score. More importantly, you'll see where the redundancy is hiding.

Open the dashboard to watch prompts in real time:

pf dashboard --watch ./src/
Enter fullscreen mode Exit fullscreen mode

Port 3000 opens. Every time you call an LLM, you see it log: model, input tokens, output tokens, cost, latency. No guessing.

For production, wire up the SDK:

import { PromptFuel } from 'promptfuel/sdk';
import Anthropic from '@anthropic-ai/sdk';

const pf = new PromptFuel();
const client = pf.wrapClient(new Anthropic());

const response = await client.messages.create({
 model: 'claude-3-5-sonnet-20241022',
 max_tokens: 1024,
 messages: [{ role: 'user', content: 'your prompt' }]
});

// Automatically tracked. One line changes nothing
console.log(pf.getMetrics()); 
// { totalTokens: 342, totalCost: $0.008, calls: 1 }
Enter fullscreen mode Exit fullscreen mode

Real numbers

Agent-Max before: ~1,847 tokens/week across all platforms.

Agent-Max after (trimmed + downgraded safe calls to Haiku): 1,094 tokens/week.

40% reduction. No quality loss. Three hours to audit and implement.

That's not a benchmark. That's a real app, real prompts, real data.


Stop guessing about your token spend. Measure what you're actually doing.

npm install -g promptfuel
Enter fullscreen mode Exit fullscreen mode

https://promptfuel.vercel.app?utm_source=devto&utm_medium=social&utm_campaign=max

Top comments (0)