All posts
    Blog2 min read

    8 Million Tokens in Two Days, Euhm What?

    Sammy Deprez

    Part 1 of a 5-part series on cutting the token cost of an AI agent

    Yes you read that well. One tester, two days, 8.48 million input tokens. On a dev environment.

    I'm currently helping a client build an internal AI assistant. A proper agent: it searches for tools, remembers things about the user, reads screenshots and pulls exports from the CRM. So you expect a lot of tokens. But when I opened the spend logs on a Monday morning, I still had to look twice.

    So let's dig in.

    One conversation, 5.3 million tokens

    Most of it came from one long research conversation: 44 model calls, 5.3 million input tokens. The prompt grew from 16K tokens on the first call to 179K on the last.

    My first thought: the context is too long, let's trim it. Clear old tool results, summarise earlier, cap what tools return. The usual stuff.

    And yes, we built all of that. But it turned out not to be the biggest problem.

    The split that changed everything

    Prompt caching was switched on. So I looked at how those 5.3M tokens were actually billed:

    Billed asTokensShare
    Cache write4.4M83%
    Cache read0.9M17%

    83% was written to the cache. And a cache write costs more than normal input. So the cache that should save us money was charging us extra for almost every token, and then barely reading anything back.

    Two more things stood out in the logs:

    • Almost every turn's first call missed the cache completely, even seconds after the previous turn.
    • From about 80K tokens, calls within the same tool loop started missing too.

    That is not a "context too long" problem. Something was breaking the cache.

    What's coming

    In the next posts I'll show how we found the cause and what we changed. Every step was measured on the same replayed benchmark conversation of about 35 model calls, with tool discovery, memories, images and big data exports. Same model, same script, before and after.

    The end result on Claude Sonnet:

    $7.35 → $1.37 per conversation. About 81% cheaper. And about 90% with one more change we haven't switched on yet.

    Here's the plan, one post a week:

    1. 8 Million Tokens in Two Days, Euhm What? (this post)
    2. Your Cache Hit Rate Is Your Real Token Bill (24 November)
    3. Four Ways Our Agent Broke Its Own Cache (1 December)
    4. Shrinking the Context Without Shooting Yourself in the Foot (8 December)
    5. The Bugs Were Hiding in the Paths We Never Ran (15 December)

    PS: If you run agents in production and only look at "tokens used", go check your cache writes. I'll show you how in the next post.

    Next (24 November): Your Cache Hit Rate Is Your Real Token Bill

    • AI Agents
    • Prompt Caching
    • LLMOps

    Keep reading.

    New notes, straight to your inbox.

    One email when something new ships. No spam, unsubscribe anytime.

    Cookie Preferences

    Essential cookies keep the site working. With "Accept all" we also use Google Analytics and the LinkedIn Insight Tag to see how the site is used and which kinds of companies visit. Nothing is loaded unless you accept. Learn more in our Privacy Policy