Every Agent Run Should Come With a Receipt
A per-task cost receipt, tiered model routing, and budgets that degrade gracefully — the real drivers of AI agent cost, measured with the open-source tokenecon package on AWS.
# Every Agent Run Should Come With a Receipt
Here is a question most teams building AI agents cannot answer: what did that task cost?
Not the monthly cloud bill. Not the average cost of one model call. The task — the support ticket the agent resolved, the report it generated, the code fix it attempted. Ask, and you usually get a shrug and a link to a billing dashboard that totals everything and explains nothing.
I ran into this while building agent systems on AWS. A single chat call has a predictable price. An agent does not: it loops, calls tools, reads documents, retries when it is unsure. Every one of those steps is another trip through a priced model. The total is real money, but it stays invisible until the invoice arrives — and by then you cannot tell which tasks earned their cost and which ones burned it.
So I built the measuring tool first, then used it to look at what actually drives agent cost. The tool is an open-source package called tokenecon. This post is about what the numbers say, and the pattern that falls out of them.
## What actually drives the cost of an agent task
Two findings surprised me, and they are worth separating because teams usually chase the wrong one.
**Finding 1: the model you pick matters 28× more than almost anything else.**
Take one fixed job — a SWE-bench-style code repair task using 3.52 million tokens — and price it across models at current public prices:
| Model | Cost for the same task |
|---|---|
| MiniMax M2.5 | **$1.37** |
| DeepSeek V4 Pro | $2.79 |
| Claude Sonnet 5.5 | $9.86 |
| Claude Opus 4.6 | **$38.72** |
|---|---|
| MiniMax M2.5 | **$1.37** |
| DeepSeek V4 Pro | $2.79 |
| Claude Sonnet 5.5 | $9.86 |
| Claude Opus 4.6 | **$38.72** |
Same task. Same tokens. A 28× spread, decided entirely by which model name sits in your config file. (The two end prices are published figures; the middle rows are computed from October 2026 list prices using tokenecon, so you can reproduce them.)
**Finding 2: your framework's overhead is real, but it is the small lever.**
Measured on identical tool-use tasks with a mock model — so the numbers isolate pure framework overhead — most frameworks add only a few percent: PydanticAI about 1.05×, Google ADK 1.11×, the OpenAI Agents SDK 1.14×. The heaviest measured, SmolAgents, came in at 3.9×. Worth knowing, but compare the scales: framework choice moves your bill by percent. Model choice moves it by 28×. Teams routinely spend weeks debating frameworks and zero minutes governing which model each task lands on.
One warning before you rush to the cheapest model: the honest unit is **cost per successful task**, not cost per call. A budget model that needs three attempts can cost more than a flagship that gets it right once. Cheap per token is not the same as cheap per result.
## Step 1: make every run produce a receipt
You cannot govern a cost you cannot see per task. tokenecon's answer is a receipt: every agent run records each step — tier used, tokens in and out, cost, confidence — so a finished task has an itemized price tag.
For live agents, the `CostTracker` attaches to a Strands Agents agent (the open-source framework most of us run on Amazon Bedrock) and prices each event-loop cycle using the token counts the provider already reported. No estimation, no heuristics — the same usage numbers your bill is built from, organized by task instead of buried in an invoice:
```python
from tokenecon.integrations.strands import CostTracker
from tokenecon.integrations.strands import CostTracker
tracker = CostTracker(tier="medium")
agent("Summarize our Q3 cloud spend.")
print(tracker.receipt(agent, "Summarize our Q3 cloud spend.").pretty())
# step 1: tier=medium in=1840 out=312 cost=$0.003088 event-loop cycle 1
# step 2: tier=medium in=2210 out=148 cost=$0.002802 event-loop cycle 2
# total_cost : $0.005890
```
agent("Summarize our Q3 cloud spend.")
print(tracker.receipt(agent, "Summarize our Q3 cloud spend.").pretty())
# step 1: tier=medium in=1840 out=312 cost=$0.003088 event-loop cycle 1
# step 2: tier=medium in=2210 out=148 cost=$0.002802 event-loop cycle 2
# total_cost : $0.005890
```
Receipts are the unit of cost observability. Collect them and patterns jump out fast: which task types are expensive, which prompts balloon, which agent is quietly retrying its way through your budget.
## Step 2: tier your models
Once you can see per-task cost, the fix is routing. Most steps in most agent runs are easy — summarize this, extract that, format the other thing. Only a minority genuinely need your strongest (and most expensive) model.
tokenecon's tiered router scores each request for difficulty, sends it to the cheapest tier that can handle it, and escalates to a stronger tier when confidence comes back low. The arithmetic is why this matters: in the reference model, if roughly one step in ten truly needs the flagship and your tiers differ by about 30× in price, tiered routing lands near **13% of the all-flagship bill** for the same work. Even if your real numbers are less tidy, the direction is not close.
## Step 3: give every task a budget
Visibility plus routing still leaves one gap: nothing stops a runaway run. So the third piece is a per-task budget, set before the run starts — five cents for a summary, two dollars for a deep research task, whatever the work is worth to you.
The important design choice: budgets should *degrade*, not fail. If the cheapest first step would already break the budget, serve a cached answer for $0. If escalating to the next tier would break it, keep the current answer and mark the run degraded. The user gets a slightly weaker answer instead of an error — and you get a record showing exactly where the budget bit. A runaway agent becomes a capped agent.
## Try it
```bash
pip install tokenecon
tokenecon demo # sample tasks vs. the all-large baseline
tokenecon demo --budget 0.01 # same tasks under a 1¢ budget — watch the guardrails
```
pip install tokenecon
tokenecon demo # sample tasks vs. the all-large baseline
tokenecon demo --budget 0.01 # same tasks under a 1¢ budget — watch the guardrails
```
The package is dependency-free (Python 3.9+, MIT). The router, the cost model, and the Strands CostTracker are all in the repo: https://github.com/karmendra8386/agentic-ai-token-economics — issues and PRs welcome, especially from anyone running agents at a scale where the bill has started making decisions for them.
## The takeaway
An agent's cost is not a billing problem; it is an architecture problem that shows up on an invoice. Price every task with a receipt, route each step to the cheapest model that can do it well, and cap every run with a budget that degrades gracefully. Do those three things and the monthly bill stops being a surprise — it becomes a number you chose.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article