Build an AI SDLC Software Factory with Claude Code starts 12 December. Enrolment closes in 9 days
Courses / Cut AI Agent Costs with Token EconomicsProLesson 2 of 86:32

Measure AI agent cost per task, not per bill

Which number tells you a release saved money? Param Harrison explains why the monthly bill and the cost per call do not give you the full picture. The same task can cost very different amounts from one run to the next. An agent is a probabilistic system. So your traces need to record cost per task, per feature and per customer. A cheap call that fails can cost more, because the retries add up. Run for a while and use the median, not one measurement. He also shows why companies like Intercom bill by outcome. After this lesson you can add a cost eval to each release. You change one thing at a time, so you can measure it.

What this covers: cost evals per release, and cost per task, feature and customer. It also covers run to run differences, API load tests and failed cheap calls. Then the median cost, outcome billing, and one change per release.

Full session: Cut AI Agent Costs with Token Economics

#aiagents #llm #aicost

Chapters

  1. Add a cost eval to each release
  2. Map the bill to tasks and customers
  3. Why load tests do not work here
  4. Cost per task done right
  5. Billing by outcome
  6. Change one thing per release

Transcript

Add a cost eval to each release

Like you need to put an evaluation layer whenever you are releasing a new version for cost as well. You need to put like what is your floor and whether this eval is measuring against that floor. Is it going to work or not work? You need to evaluate that.

Map the bill to tasks and customers

Know what each task cost is more important, like your monthly inbox, like invoice will show like this is the cost, but you need to able to map that invoice into which feature we have released and for which customer and what step has been done, and you will be able to see, like, okay, this is what this is what the reason for the cost you need to make sure the total alone is not the matter, but rather your traces need to record what is the cost per task per feature or per customer, so that you will be able to understand what is the average, and for that average, because each agentic run will cost very differently because it is still a probabilistic system. First cost might be 0.05 on that, and the second cost can easily go to 0.2. So the difference is almost 4x. So you can you you might think this might not happen, but it can easily happen between run for same task as well. So that is very very important when you are working in a deterministic or non-deterministic

Why load tests do not work here

system. In a normal API, this is not the case. Your resource allocation is going to work almost every time. So if if your reply for example, when in a normal API, what do you measure? You measure your latency and throughput how it is behaving, unless and until the resources are completely you know jammed, then only your latency is going to grow, but you will be able to measure that with a simple load test or something which can measure like how many requests which can withstand for this system, and you will be able to design your system accordingly. But for cost, you still need to you for your AI system you still need to design that, but in a reverse process, you can't just find out, but rather you need to create the evaluation and you need to create the budget at what point, how many turns it can run, and so on. That is the only way you can able to handle that.

Cost per task done right

What are all the ways we can able to cut? Which numbers tells you a release saved money? The monthly bill cost per call, cost per task done right. So oftentimes the monthly bill only provides this is the cost. Cost per call will provide okay, this is the cost for this call, but this won't provide you the big picture. Like each call, even though the query is going to be the same, the cost per call is going to be different. So you need to create like what is the exact cost for that particular task, and then you need to average out okay, this is the average for this task which is happening, and for each task inside your agentic loop, you need to measure exactly what is the cost which is going on. So a cheap call that fails will cost more because the number of retries will increase. So oftentimes this you you might see in your coding agent as well. For example, you spin up Opus 5.5 and you provide a task, most probably within one turn itself, Opus will able to proceed. And if you open with Haiku and you are trying with that, probably it will take eight turns. Now, if you see look at the cost which happened, cost per task finished, probably opa Opus might cost the same as your your Haiku as well. This is again like the same task can cost 30 times more as well. in many of the agentic cases, this is one of the one of the things which is not measured. They will measure only one time, like okay, this will cost around this, and they will budget it accord accordingly. But in a probabilistic system, this is not the way you can measure it. You need to run at least for a duration, and you need to find what is the median, and you need to understand, okay, this is the cost which will happen for a for a longer period.

Billing by outcome

Now, as you see, this is one of the things where most of the companies have land because of that, they started to provide their billing based on the task accomplished. What is the outcome which is accomplished? Based on that, they provide their billing. Why? Because this will provide much more clarity for end user that okay. I accomplished one of the outcomes, and also it will provide much more clarity for them to you know have more granular cost and budgeting, which is there. So, based on what they exactly want in terms of business goal, revenue goal, they can set the price and they can accelerate based on that. So, for that to happen, they need to know, like, for example, if Intercom is able to say, like for every outcome, we are saying one dollar, that means they they clearly know what is the cost per unit, and they need to understand that part of it.

Change one thing per release

Change one thing per release. So, this is one of the biggest things in terms of cutting the cost. Oftentimes, if we try to change too many parameters, then it will be harder to measure what is the reasoning behind it.

This lesson comes with Pro, $149 a year: Get Pro. This lesson is cut from the free Lightning session Cut AI Agent Costs with Token Economics. The Live Labs build the same system with you, free, on Thursdays: see the Live Labs.