Skip to content
AgenticAIWiki
  1. Learn
  2. Part 13
  3. 71. Cost at scale
  4. 71.1

Lesson 71.1 · 1 of 6 · 4 min read · Reviewed 24 Nov 2026

Unit economics of an AI feature

By the end, you can

  • Work out the unit economics of an AI feature.
  • Find the cost per task, not just per call.

“The model costs X per million tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id.” is the start of the sum, not the answer.

Cost per task

cost per task = sum over calls (input tokens x input price
                              + output tokens x output price
                              + cache writes and reads at their prices)
              + tool and search costs
              + retries and failed runs
              + infrastructure (workers, storage, vector DB)

An agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. that makes 8 calls with a growing context costs far more than 8 times a single short call, because each call re-reads the conversation so far.

Cost per outcome

Not every task succeeds. If 70% of agent runs resolve the ticket:

cost per resolved ticket = cost per run / 0.70

Improving success rate cuts cost per outcome, sometimes more than switching to a cheaper model.

Compare with value

Metric Example question
Cost per resolved ticket Is it below what a human-handled ticket costs?
Cost per active user per month Does the plan price cover it with margin?
Cost per document processed Does the customer pay enough per document?

Use your tracesTrace: A record of everything that happened during one request or agent run, as a tree of timed steps. (chapter 67) for real numbers. Look up current prices on the pricing page rather than hard-coding them in planning docs.

Key points

  • Measure cost per useful outcome (a resolved ticket, a finished report), not only per API call.
  • Cost per task = calls per task x tokens per call x price, plus retries, tools and infrastructure.
  • Compare that cost with the value of the outcome to see if the feature pays for itself.
Hands-on labRuns in the Playground

Work out cost per resolved ticket

Turn trace data into cost per call, per run and per resolved ticket, and compare it with a human ticket.

You will have: A cost script that prints the three unit costs and says whether the feature pays for itself.

Steps

  1. Run the starter: it says the feature pays for itself.
  2. Add tool calls and infrastructure to each run's cost.
  3. Divide by the success rate, since failed runs cost money too.
  4. Work out the same figure at a 90% success rate and compare.

Done when

  • Cost per run is about 113.7 credits.
  • Cost per resolved ticket is about 162.4 credits, above the human ticket.
  • At 90% success the feature pays for itself.

Open in the Playground No API key needed.

Starter code (Python)
# Work out cost per run and cost per resolved ticket from (illustrative) trace data.
# Rates are made-up credits per 1,000 tokens. Use your own numbers from the current pricing page.
RATES = {"input": 3.0, "output": 15.0, "cache_read": 0.3}
TOOL_CREDITS = 2.0           # each search or lookup the agent calls
INFRA_PER_RUN = 1.5          # workers, storage and vector database, spread per run
HUMAN_TICKET_CREDITS = 150   # what a human-handled ticket costs, in the same units


def agent_run(steps, resolved, tools):
    # Each step re-reads the conversation so far, so input grows with every call.
    calls = [{"input": 1500 + 1200 * i, "output": 300, "cache_read": 4000 if i else 0} for i in range(steps)]
    return {"calls": calls, "resolved": resolved, "tools": tools}


RUNS = [agent_run(3, True, 2), agent_run(5, True, 4), agent_run(8, False, 7), agent_run(4, True, 3),
        agent_run(6, True, 5), agent_run(9, False, 8), agent_run(3, True, 1), agent_run(5, True, 4),
        agent_run(7, False, 6), agent_run(4, True, 3)]


def call_cost(c):
    return sum(c[k] / 1000 * RATES[k] for k in RATES)


def run_cost(run):
    # TODO 1: add the tool calls (TOOL_CREDITS each) and INFRA_PER_RUN to the model calls
    return sum(call_cost(c) for c in run["calls"])


per_call = [call_cost(c) for r in RUNS for c in r["calls"]]
per_run = [run_cost(r) for r in RUNS]
success = sum(r["resolved"] for r in RUNS) / len(RUNS)
avg_run = sum(per_run) / len(per_run)
per_resolved = avg_run  # TODO 2: failed runs still cost money; divide by the success rate
print(f"average cost per call: {sum(per_call) / len(per_call):.1f} credits")
print(f"average cost per run: {avg_run:.1f} credits")
print(f"success rate: {success:.0%}")
print(f"cost per resolved ticket: {per_resolved:.1f} credits")
print("pays for itself" if per_resolved < HUMAN_TICKET_CREDITS else "costs more than a human ticket")
better = avg_run  # TODO 3: the same sum at a 90% success rate
print(f"if success rose to 90%: {better:.1f} credits per resolved ticket,", "pays for itself" if better < HUMAN_TICKET_CREDITS else "still too costly")
Show a solution
# Work out cost per run and cost per resolved ticket from (illustrative) trace data.
# Rates are made-up credits per 1,000 tokens. Use your own numbers from the current pricing page.
RATES = {"input": 3.0, "output": 15.0, "cache_read": 0.3}
TOOL_CREDITS = 2.0           # each search or lookup the agent calls
INFRA_PER_RUN = 1.5          # workers, storage and vector database, spread per run
HUMAN_TICKET_CREDITS = 150   # what a human-handled ticket costs, in the same units


def agent_run(steps, resolved, tools):
    # Each step re-reads the conversation so far, so input grows with every call.
    calls = [{"input": 1500 + 1200 * i, "output": 300, "cache_read": 4000 if i else 0} for i in range(steps)]
    return {"calls": calls, "resolved": resolved, "tools": tools}


RUNS = [agent_run(3, True, 2), agent_run(5, True, 4), agent_run(8, False, 7), agent_run(4, True, 3),
        agent_run(6, True, 5), agent_run(9, False, 8), agent_run(3, True, 1), agent_run(5, True, 4),
        agent_run(7, False, 6), agent_run(4, True, 3)]


def call_cost(c):
    return sum(c[k] / 1000 * RATES[k] for k in RATES)


def run_cost(run):
    return sum(call_cost(c) for c in run["calls"]) + run["tools"] * TOOL_CREDITS + INFRA_PER_RUN


per_call = [call_cost(c) for r in RUNS for c in r["calls"]]
per_run = [run_cost(r) for r in RUNS]
success = sum(r["resolved"] for r in RUNS) / len(RUNS)
avg_run = sum(per_run) / len(per_run)
per_resolved = avg_run / success
print(f"average cost per call: {sum(per_call) / len(per_call):.1f} credits")
print(f"average cost per run: {avg_run:.1f} credits")
print(f"success rate: {success:.0%}")
print(f"cost per resolved ticket: {per_resolved:.1f} credits")
print("pays for itself" if per_resolved < HUMAN_TICKET_CREDITS else "costs more than a human ticket")
better = avg_run / 0.9
print(f"if success rose to 90%: {better:.1f} credits per resolved ticket,", "pays for itself" if better < HUMAN_TICKET_CREDITS else "still too costly")
Quick checkWhich number best tells you whether an AI support agent is worth its cost?
How sure are you?
Pick an answer and how sure you are