one review cost 490,000 tokens. now it costs about 32,000
lagos
I work on an AI agent that reviews cases, one at a time. It pays an AI company for every word it reads and writes.
The prepaid balance behind it ran out much faster than anyone expected. That made me ask a question nobody had asked yet: what does one review actually cost?
The answer was about 490,000 tokens. A token is a piece of a word, and AI companies bill by them. This is what I learned getting that number down.
Read the Error Before You Guess
The first thing I got wrong was guessing. The agent was failing, and I spent time reasoning about rate limits before I read the actual error text closely. It said "You have no credits remaining." One line settled what an hour of reasoning couldn't.
It also answered the most useful question: is this their problem or ours? If an AI company is having an outage, you wait. If the problem is on your side, you act. Nothing was broken on their end. Everything that made it expensive was in our code.
Three Numbers, Multiplied
Cost turned out to be three numbers multiplied together, and nobody was watching the total.
How many reviews ran. Clearing a pile of waiting work all at once means dozens of reviews back to back. A balance that looks fine for a normal day can empty in half an hour.
How big each review was. This was the surprise. Where did 490,000 come from? An agent works in steps. It reads its instructions, decides what to look up, looks it up, and goes again. A review took about 11 steps. Every step sent about 28,000 tokens of instructions and tool descriptions again, and re-read every result gathered so far. So the cost doesn't grow step by step. It snowballs.

How much was wasted. A failed review was retried up to 5 times, from scratch, and every try was paid for. A case whose review gave up was put back in the queue by an hourly sweep, forever. So a broken case could be paid for again and again, with nobody noticing.

Stop the Bleeding First
A loop or a retry multiplies everything else, so those went first.
- No more endless loop. After 3 failed runs, the sweep stops re-queueing a case. A person can still press retry.
- Fewer paid retries. Not all failures cost the same. If the AI company refuses straight away, you pay nothing, so it can keep its 5 tries. If the model did 10 steps of work and then timed out, you paid for all of it. Those now get 2 tries, not 5.
- A speed limit for big piles of work. A set number of reviews run at once, and the whole pass stops the moment the AI company says "slow down" or "no credit".
- Pause instead of retry. When there's no credit, a review keeps its place in line and doesn't count as a failure. The queue waits, tests again every 15 minutes, and carries on by itself once the money is back.
That last one sounds small. Without it, a case could get flagged for a person because we ran out of credit. That's our problem, not the case's.
Then Make Each Review Smaller
With the waste stopped, the next lever was the 490,000.
Shorter tool descriptions. The descriptions of the tools the agent could use were about 9,700 tokens on their own, sent on every step. Each kind of record had its own tool, each with a long explanation. Now every kind is one short line, and the long explanation comes back with the result, only when that kind is actually read. That took 9,700 tokens down to about 2,600. Tools it never used are gone completely.
Code gathers the facts first. On every review, the model was spending most of its steps looking up the same basic facts it always needs. Now plain code reads those first and hands the model one short sheet in its first message. The model only goes looking when it finds something worth chasing.
Cache what repeats. The instructions that are the same on every step are now reliably cached, so after the first step they cost about a tenth.
Smaller results. Long results are cut off, and lists come back 10 rows at a time unless the model asks for more.
One thing I didn't do: put a cap on tokens per review. The obvious move was to stop the model at 90,000 tokens. But a token cap stops the model exactly when a case is unusual and needs a closer look. So 90,000 is a target for the average, not a wall. The only hard limits are a cap on lookups per review and a spending limit per run, which catch a model that gets stuck, not one that is being careful.
The Numbers, Honestly

A failed review used to be paid for up to 5 times and then loop forever. Now it's paid for at most twice, and a failure because of no credit costs nothing and waits.
Before the fixes went live, all I had was an estimate from the size of the requests: about 140,000 tokens a review.
The real number came in far lower. Over the first 50 reviews, a review used about 32,000 tokens on average, and it held there over more than 200. That's about 458,000 fewer than before, a cut of about 93%. These numbers are from our own tracking. I haven't checked them against the AI company's bill yet, and I will.
That also means my plan was off. I expected about 21,000 tokens of instructions to go out on each of 4 or 5 steps. That alone would be well over 32,000. So the real reviews are taking fewer steps, or reading less each step, than I planned for. That's the next thing to measure.
A Dashboard Is Not an Alert
A page that shows the balance wouldn't have helped, because nobody is looking at a page at 2am.
So now there are checks every 10 minutes: out of credit, reviews stalled, failure rate, spend per hour and per day, cost per review, a growing backlog. Each one posts when it starts, again every 2 hours while it lasts, and once when it clears.
What I'd Tell Myself Next Time
- Read the error before you guess. One line of real error text beats an hour of reasoning.
- Ask "ours or theirs?" first. It decides whether you wait or act.
- Look for multipliers. Cost is volume × size × waste. Fix the loop and the retries before anything else.
- Free failures and paid failures are different. Retry rules should know which is which.
- Measure before cutting. Knowing what made up the 490,000 is what made the savings obvious.
- A dashboard is not an alert.
- Merged is not live. Check the deploy happened before you judge a fix.
The agent itself was fine the whole time. It did what we asked it to, and it did it 490,000 tokens at a time.