Reduce Token Usage in AI Agents: Measured Results

Test results on how to reduce token usage in AI agent sessions

The biggest way to reduce token usage costs in an AI agent, a new measured test found, wasn’t trimming anything. It was leaving the top of the prompt alone. One timestamp in the system prompt made an identical session cost 7.8 times as much.

Why agents burn so many tokens

Each step of an agent is a fresh model call that resends everything: the system prompt, tool definitions, every prior message and every tool result. One big file read or an error log can add thousands of tokens that are then paid for again on all later steps.

Caching softens the cost. Providers discount input they’ve processed before, though only when the beginning of the prompt matches exactly. If something near the top changes, whether a timestamp or an old message that was edited, the rest is billed at full new-input rates.

How to Reduce Token Usage in AI Agents (Measured)
Image: OpenRouter Blog

How the test was run

The team took one synthetic coding-agent history, about 1 million characters (260K tokens), and replayed it as 40 requests to openai/gpt-6-luna at low reasoning effort. The model’s rates that day were $0.10 per million fresh input tokens, $0.01 per million cached ones and $0.50 per million output tokens. Every setup was run on three sessions.

What helped reduce token usage and cost

Results by setup:

  • Changing prefix, with a timestamp at the top: $0.658 per session, and cached input fell from 95% to zero
  • Stable prefix with a constant session ID: $0.084 with 95% of input cached
  • Re-trimmed old tool outputs on every step: $0.263, even though input fell from 5.25M to 2.09M tokens
  • Tool outputs capped once: $0.054, the cheapest, with input down 36%
  • Chunked compaction: a little more than capping, but the smallest final prompt

Both prefix runs sent an identical 5.25M input tokens. What changed was the price: $0.125 per million to write a cache entry nobody reused, versus $0.01 to read one. The uncached run was also the slowest, 170 seconds against 149.

Trying to reduce token usage the wrong way can backfire. Fewer tokens did not mean lower cost. Re-trimming cut input by 60% but edited messages the previous step had cached, so the cache broke on every request.

Practical steps to reduce token usage

First, freeze the top of the prompt. Take timestamps and request IDs out of the system prompt, list tools in the same order every time and put the current time in the newest user message. Pass one session_id throughout so requests keep landing on the provider that holds your cache. That routing lapses after 60 idle minutes.

Second, shorten each tool result a single time, as it is added. The test kept 800 characters from each end and inserted a note on how much was cut. After that, leave it as is.

Third, compact long sessions piece by piece. Once history passed 300,000 characters, all but the latest eight messages were summarized in 16,000-character batches, and earlier summaries stayed untouched. The last prompt dropped from 260K to 63K tokens with 85% of input still cached. Where cache reads are cheap, compaction saves less than capping does, so reach for it when prompt size or response time is the issue.

Don’t summarize a summary. The team’s first compaction attempt fed the previous summary back in, and in that one session both the ticket ID and the user’s early rule vanished. The model got 1 of 4 questions right. Repeated summarizing is the suspected cause, though it wasn’t tested alone.

Reasoning budgets and what to log

Turn reasoning effort down for routine steps. One DeepSeek V4.1 Flash call burned its entire 4,000-token output allowance thinking about a simple triage request, then sent back nothing, and the charge still applied. Low effort cured it. Some endpoints require reasoning and reject requests that try to turn it off, so lowering effort is the safer route.

To audit your own agent, record prompt tokens, cached tokens and cost on each response. Check step 2 first, because nothing exists to hit on step 1. With automatic caching and a prompt above 1,024 tokens, most input should read as cached by that point. Anthropic models also need cache breakpoints.

The caveat is scope: one model, one provider’s automatic caching and a synthetic session. Savings will differ where caching prices differ, but the pattern holds wherever a stable prefix earns a discount: edit as little as possible and don’t touch what’s already cached.

Source: OpenRouter Blog

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.