IamBishal

The Bill for One Ticket: Agent Cost per Task, Measured

My cost-per-task article runs its planning model on numbers marked "illustrative throughout", then says to fill it with real tickets before you commit. So I did.

A support agent works 24 tickets under seven cost levers, 336 tickets on Claude Sonnet and Haiku, and the article's planning model is filled with the real numbers. A cheaper model was the biggest lever, a broken cache the costliest mistake.

cost per ticket with Haiku, every ticket resolved
−95%
a timestamp in the system prompt, silently
+125%
real input against step-one-times-steps
2.1×
conditions the model predicted within 25%
7 / 7
  • Experiment
  • 7 min read
  • AI Architecture
  • Evals & AgentOps
  • Python
  • Claude
  • AI agents
  • Cost modelling
Figure 1. Token cost of one ticket, per condition

Overview

In "AI Agent Cost per Task" I argued that an agent's cost depends on its structure more than on its token price, and built a planning model, ticket_cost.py, to show which levers move the bill: re-sent history, prompt caching, a history cap, routing to a cheaper model, retries. Every input in it was illustrative, and the article ends: "Fill the model with ten real tickets before you commit."

So I ran the real thing. A support agent works 24 tickets over real Kestrel Outfitters orders, one ticket per attempt in a fresh window, with tools that return the full record an untrimmed API would. Seven conditions change one lever at a time from a cached Sonnet baseline: no caching, a timestamp at the top of the system prompt, a history cap with a running summary, Haiku for every call, two Haiku calls before handing over to Sonnet, and switching models on every call.

Every call is priced from the usage the API reports. The article's model is copied verbatim, and a test checks it reproduces the article's printed output to the cent. It is then filled from an 8-ticket pilot of the baseline and asked to predict every condition. 336 tickets cost USD 9.09.

The pilot caught a flaw of my own: every condition sent the same first message for the same ticket, so later conditions read earlier conditions' caches and looked far cheaper. A random tag per job fixed it; the affected runs are archived and disclosed.

The results turned two of the article's claims around. Haiku resolved every ticket and cut cost by 95%, against caching's 46%, so a cheaper model was the biggest lever on these tickets. Switching models on every call saved money instead of costing it. A timestamp in the system prompt cost 125% more, silently. And once given real step counts, the planning model predicted every condition within 25%.

Did it hold up?

Full results

The hypothesis, written down before the first run, and what the results said.

  1. Confirmed

    History makes input grow faster than linearly: one step's input times steps underestimates a real attempt.

    Real input was 2.1x the naive estimate at only 4.5 calls per ticket.

  2. Confirmed

    Prompt caching is the biggest token lever among the structural changes.

    No caching cost 86% more, more than the history cap (+73%); routing saved 17-24%.

  3. Confirmed

    A cache break is silent and expensive, and a prompt below the minimum caches nothing.

    A timestamp in the system prompt cost 125% more, worse than no cache, with 0 cache reads and no error. A 436-token prompt cached nothing.

  4. Partly

    Routing pays only when it keeps the cache: phase routing saves, switching every call costs more.

    Phase routing saved 24%, but switching saved 17% too: at a 1/20 price gap the cheap calls outweigh the lost cache.

  5. Confirmed

    A history cap loses on a short run.

    It cost 73% more: once it folds history, every call rewrites the cache.

  6. Wrong

    A cheaper model is a weaker lever than structure, per resolved ticket.

    Haiku cut cost by 95% against caching's 46%, and resolved every ticket, so no failure cost diluted the saving.

  7. Partly

    The planning model, filled from a pilot, predicts each condition within 25% and ranks the levers.

    4 of 7 within 25% on the pilot's median steps; all 7 over the real step mix. One adjacent pair ranked the wrong way.

What it does

  • One support ticket per attempt, in a fresh window, with realistic verbose tools
  • Seven cost levers changed one at a time from a cached Sonnet baseline
  • Every call priced from the API's reported usage, cache writes and reads included
  • The article's planning model vendored verbatim, tested against its printed output
  • The model filled from an 8-ticket pilot, then asked to predict every condition
  • A silent cache break and a below-minimum prompt, both caught in the cache fields
  • Per-job tags so no condition can read another's cache
  • A fake model with a cache simulator that proves the cost accounting offline

How it's built

  1. Inputs

    • 24 support ticketsReal orders, still delivered
    • The article's modelticket_cost.py, verbatim
  2. Seven cost levers

    • Cached Sonnet baseline
    • No cache; a cache break
    • History cap with summary
    • Haiku for every call
    • Phase routing; switching
  3. Outputs

    • Ticket bills336, from reported usage
    • Model vs measuredError per condition
    • Cache behaviourHits, writes, silent misses
conditions.py and planning_model.py
# conditions.py: one cost lever changed at a time from a cached Sonnet baseline.
@dataclass(frozen=True)
class Condition:
    id: str
    caching: bool = True
    timestamp: bool = False          # "Current time: ..." at the top of the system prompt
    history_cap: int | None = None   # tool exchanges kept word for word
    cheap_first: int = 0             # phase routing: the first N calls on Haiku
    alternate: bool = False          # per-step switching
    all_haiku: bool = False

    def model_for(self, step: int) -> str:
        if self.all_haiku or step < self.cheap_first or (self.alternate and step % 2 == 0):
            return HAIKU
        return SONNET

# planning_model.py: the article's ticket_cost.py, verbatim, filled from the pilot.
def fit(baseline_attempts):
    steps = round(median(len(a["calls"]) for a in baseline_attempts))
    added = [b["window_tokens"] - c["window_tokens"]
             for a in baseline_attempts for c, b in zip(a["calls"], a["calls"][1:])]
    return Run(steps=steps,
               prefix_tokens=round(mean(a["calls"][0]["window_tokens"] for a in baseline_attempts)),
               tokens_added_per_step=round(mean(added)),
               output_tokens_per_step=round(mean(c["output_tokens"] for a in baseline_attempts for c in a["calls"])),
               tool_cost_per_call=0.0, price_in=2.00, price_out=10.00, cheap_in=0.10, cheap_out=0.50)

Figures

Figure 1. Token cost of one ticket, per condition1 of 3

What I learned

  • Measure the step count, then use the distribution. The article's model was 22-43% high on a whole-number median and within 25% everywhere over the real mix.
  • A cheaper model is only a weak lever when it fails. Haiku resolved every ticket here and cut the bill by 95%.
  • A cache break costs more than no cache: every call rewrites its prompt at the write premium, and nothing raises an error.
  • Automatic caching caches nothing on its own before the conversation, so tickets never shared their identical tools and system prompt.
  • At a 1/20 price gap, routing wins even when it loses the cache; the article's 1/5 assumption flips the switching result.
  • A history cap breaks the cache on every call once it starts folding; on short tickets it costs far more than it saves.
  • Test your harness for shared state. My first pilot let conditions read each other's caches, which made the article's model look up to 288% wrong on routing.

Next steps

  • Harder, ambiguous tickets where a cheaper model fails, to test the failure-cost side
  • Explicit cache breakpoints after the tools and system prompt, to share the prefix
  • A planning model that takes a distribution of step counts
  • Longer tasks (12+ calls), where the quadratic history term dominates

Run it yourself

Everything on this page comes from code and data in the repository. The dry run is free and needs no API key. A full live rerun costs about USD 9.

Terminal
git clone https://github.com/bishal-saha/ai-lab-code.git
cd ai-lab-code/agent-cost-per-task-benchmark
uv sync
uv run bill-for-one-ticket --dry-run      # a fake that bills like the API, $0
mv results results-published              # the live runner resumes from committed results
cp .env.example .env                      # then add your ANTHROPIC_API_KEY
uv run --env-file .env bill-for-one-ticket --max-usd 12
uv run python -m bill.report

Bishal SahaLet's build together

Have a system to design, or an AI feature to get right?

Tell me about the problem. You'll get a clear, honest view of the best way forward.

  • Reply within 24 hoursOn business days, with my honest view and a next step.
  • Accepting select engagementsArchitecture, AI features and full builds.
  • Remote, worldwideWorking with startups, SMEs and enterprises.