AI Unit Economics and Token Budgets
Price per token is the wrong unit. Cost per successful task, including retries, cache use and the human work behind failures, decides whether an AI feature makes money.
5 min read / Updated / Last checked
- Format
- Calculator · Intermediate
- Who it is for
- Founders and the builders they hire
- You leave with
- Estimate cost per successful task and blended cost per task with a small calculator, then set token budgets and a margin gate from the result.
The problem
In April 2026, Datadog reported that the average number of tokens sent per AI request had more than doubled for median teams and quadrupled for heavy users, the 90th percentile of usage [1]. In an agent, one customer request can mean several model calls, each resending instructions, tool definitions and the conversation so far.
Most founders still estimate AI cost from the price list. A model costs a few dollars per million tokens, a request uses a few thousand, so a request costs a fraction of a cent, and the feature looks nearly free. Then the invoice arrives, or worse, the support team does. The estimate missed three things: an agent run is several calls, some runs retry, and every run that fails still has to be finished by a person.
The unit that decides whether a feature makes money is cost per successful task: what it costs, on average, to get one customer outcome done. This guide builds that number from token counts and published prices, shows why the success rate usually matters more than the model's price, and turns the result into budgets the system can enforce.
How it works
The calculation has five layers, from the price list up to the business.
- Cost per call. Uncached input tokens times the input price, plus input tokens read from the prompt cache times the cache-read price, plus output tokens times the output price. Output counts include reasoning tokens [4]. Prompt caching stores a repeated prefix, such as instructions and tool definitions, so later calls read it at a discount. On Anthropic's API, cache reads cost 0.1 times the base input price on most models and 0.05 times on Claude Sonnet 5.5 and Opus 5.5, while a 5-minute cache write costs 1.25 times [2].
- Cost per attempt. Calls per agent run times cost per call, plus the cost of writing the cache.
- Cost per task. Cost per attempt times attempts per task, which counts retries and reruns.
- AI cost per success. Cost per task divided by the success rate, because failed attempts are paid for too.
- Blended cost per task. AI cost per task plus the share of tasks that fail times what a person costs to finish one. This is the number to compare with what the customer pays.
Two discounts change the picture for some workloads. Anthropic's Batch API charges 50% less for input and output on requests that can wait [2], and OpenAI lists separate batch rates [3]. Batch suits overnight classification and report generation, not a customer waiting in chat.
Every input in the calculation can be measured. Token counts, cached tokens and output tokens are standard attributes on model call spans in the OpenTelemetry conventions [4], so the numbers come from your own traces, not from guesses.
From token prices to margin
Fig. 01- Tokens per callfresh, cached, output
- Cost per attemptcalls per run, cache writes
- Cost per tasktimes attempts
- Cost per successdivided by success rate
- Blended costplus human cost of failures
- Marginagainst price per task
By the numbers
- growth in average tokens per request for median teams in Datadog's 2026 data, 4x at the 90th percentile [1]
- >2x
- Batch API discount on input and output tokens for Claude models [2]
- 50%
- cache-read price relative to base input on most Claude models [2]
- 0.1x
- Claude Sonnet 5.5 input and output price per million tokens, November 2026 [2]
- $2 / $10
- gpt-6.1-terra input and output price per million tokens, November 2026 [3]
- $1 / $5
| Model | Input | Cache read | Cache write | Output |
|---|---|---|---|---|
| Claude Sonnet 5.5 | $2.00 | $0.10 | $2.50 (5 minutes) | $10.00 |
| Claude Haiku 5.5, prompts up to 100,000 tokens | $0.10 | $0.01 | $0.125 (5 minutes) | $0.50 |
| gpt-6.1-terra | $1.00 | $0.05 | $1.25 (30 minutes) | $5.00 |
| gpt-6-luna | $0.10 | $0.01 | $0.125 (30 minutes) | $0.50 |
Prices change often, which is why the table carries a date and the calculator keeps prices in one place. The Datadog figure is the reason to re-measure token counts monthly rather than once [1]: a feature's context grows whenever conversations get longer or tools and retrieved documents are added.
The price gap in the table is 20 times between the two Claude models and 10 times between the two OpenAI models. That gap looks decisive, and the worked example below shows why it often is not.
Implementation
The calculator takes prices and a measured workload and returns three numbers per model. Prices are copied from the pricing pages with the date [2][3]. Everything in Workload is an input to measure from your own traces.
"""Cost per successful task for an LLM feature. Prices in USD per million tokens."""
from dataclasses import dataclass
@dataclass(frozen=True)
class Price:
input: float
cache_read: float
cache_write: float
output: float
# Official pricing pages, read November 12, 2026. Recheck before you rely on them.
PRICES = {
"Claude Sonnet 5.5": Price(2.00, 0.10, 2.50, 10.00), # 5-minute cache write
"Claude Haiku 5.5": Price(0.10, 0.01, 0.125, 0.50), # prompts up to 100,000 tokens
"gpt-6.1-terra": Price(1.00, 0.05, 1.25, 5.00), # 30-minute cache write
"gpt-6-luna": Price(0.10, 0.01, 0.125, 0.50),
}
@dataclass(frozen=True)
class Workload: # every value here is an input you measure from your own traces
calls_per_attempt: int # model calls in one agent run
fresh_input: int # uncached input tokens per call
cached_input: int # input tokens read from the prompt cache per call
cache_writes: int # tokens written to the cache per attempt
output: int # output tokens per call (reasoning tokens included)
attempts_per_task: float # 1.0 means no retries
success_rate: float # share of tasks the agent completes correctly
human_cost: float # USD to finish a failed task by hand
def cost_per_attempt(p: Price, w: Workload) -> float:
per_call = w.fresh_input * p.input + w.cached_input * p.cache_read + w.output * p.output
return (w.calls_per_attempt * per_call + w.cache_writes * p.cache_write) / 1_000_000
def unit_economics(model: str, w: Workload) -> dict:
ai_per_task = cost_per_attempt(PRICES[model], w) * w.attempts_per_task
human_per_task = (1 - w.success_rate) * w.human_cost
return {
"model": model,
"ai_cost_per_task": round(ai_per_task, 4),
"ai_cost_per_success": round(ai_per_task / w.success_rate, 4),
"blended_cost_per_task": round(ai_per_task + human_per_task, 4),
}A worked example, with illustrative inputs: a support agent makes 4 model calls per run, each with 1,500 fresh input tokens, 4,500 cached tokens of instructions and tool definitions, and 400 output tokens. It writes 4,500 tokens to the cache once per run, needs 1.1 attempts per ticket on average, and a person costs $4.00 to finish a ticket the agent fails. Suppose evals show 85% success with the larger model and 70% with the smaller one (also illustrative).
- Claude Sonnet 5.5: $0.0452 AI cost per ticket, $0.0531 per successful ticket, $0.6452 blended.
- Claude Haiku 5.5: $0.0024 AI cost per ticket, $0.0034 per successful ticket, $1.2024 blended.
- gpt-6.1-terra at 85%: $0.0226 per ticket, $0.6226 blended.
The smaller model is about 19 times cheaper per ticket in tokens and almost twice as expensive per ticket in total, because 15 more tickets in every 100 land on a person. Raise the larger model's success rate to 95% and its blended cost falls to $0.2452. Turning off prompt caching for the same workload raises its AI cost per ticket from $0.0452 to $0.0704. In this example, success rate moves the result far more than model price or caching.
Turn the result into budgets the system enforces:
- Per-run token cap. Stop an agent run after a set number of calls or tokens and hand it to a person. Set it near twice the median run.
- Per-user daily cap. Rate limit each account so one user or one bug cannot spend a month's budget in an afternoon.
- Alert on cost per success, not on total spend. Total spend rising with usage is good news. Cost per success rising is a regression.
Test it
The calculator is only useful if it is right and stays in use. These tests check it against a hand calculation, pin the main lesson, and turn the margin target into a CI check.
"""Check the calculator by hand, then use it as a margin gate in CI."""
import pytest
from unit_costs import PRICES, Workload, cost_per_attempt, unit_economics
TICKET = Workload(calls_per_attempt=4, fresh_input=1_500, cached_input=4_500,
cache_writes=4_500, output=400, attempts_per_task=1.1,
success_rate=0.85, human_cost=4.00) # illustrative inputs
def test_matches_a_hand_calculation():
# per call: 1,500 x $2 + 4,500 x $0.10 + 400 x $10 = $7,450 per million tokens
# per attempt: 4 calls + 4,500 cache-write tokens x $2.50, all over 1,000,000
expected = (4 * 7_450 + 4_500 * 2.50) / 1_000_000
assert cost_per_attempt(PRICES["Claude Sonnet 5.5"], TICKET) == pytest.approx(expected)
def test_failures_cost_more_than_tokens():
cheap = unit_economics("Claude Haiku 5.5", Workload(**{**TICKET.__dict__, "success_rate": 0.70}))
strong = unit_economics("Claude Sonnet 5.5", TICKET)
assert cheap["ai_cost_per_task"] < strong["ai_cost_per_task"]
assert cheap["blended_cost_per_task"] > strong["blended_cost_per_task"]
def test_margin_gate():
price_per_ticket, target_margin = 2.00, 0.60 # what the customer pays, what you keep
result = unit_economics("Claude Sonnet 5.5", TICKET)
assert result["blended_cost_per_task"] <= price_per_ticket * (1 - target_margin)Expected: three passing tests. At a price of $2.00 per ticket and a 60% target margin, the allowed blended cost is $0.80, and $0.6452 passes. At $1.50 per ticket the gate fails, which is the conversation to have before launch, not after.
Then check the model against reality once a month:
- Export one week of traces and compute actual tokens per call, calls per run and attempts per task. Replace the illustrative inputs.
- Take the success rate from the eval suite and from production labels, not from a demo.
- Compare the calculator's weekly AI cost with the provider's invoice for that week. Expected: within a few percent. A larger gap means calls the traces miss, such as retries outside the agent or background jobs.
Decision
Run this calculation before setting a price, and again whenever the model, prompt or tool set changes.
- Price per outcome or per seat with a usage ceiling, never on the assumption that tokens are free.
- Spend first on raising the success rate, then on caching, then on cheaper models. The worked example shows that order of impact.
- Use batch pricing for anything that can wait [2][3].
- Enforce per-run and per-user budgets in code, and alert on cost per success.
- To get trustworthy token counts, see LLM Observability: Traces, Logs and Costs. To measure the success rate, see How to Test an AI Agent Before Customers Use It.
Sources
- [1]AI Is Hitting Operational Limits as Companies Rush to Scale, Datadog Report Finds (opens in a new tab)Datadog, April 2026
- [2]Pricing (opens in a new tab)Claude Platform Docs, November 2026
- [3]Pricing (opens in a new tab)OpenAI API Docs, November 2026
- [4]Semantic conventions for generative client AI inference spans (opens in a new tab)OpenTelemetry, November 2026
Technical guidance, not legal or security certification.
Related resources
Need a technical review of an AI-built MVP?
Discuss your build