Braj Kishore
JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
Say hi

Hiring · Building · Investing

Have a system — or a team —that needs to scale?

info@avyxon.ai

Usually replies within a day · track record here

JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
LinkedInXYouTubeSubstackInstagramThreadsFacebookDiscordGitHubTopmate
© 2026 Braj Kishore · Bengaluru, INThink Big · Start Small · Scale Fast
Agentic engineering
Lesson 21Working

Cost optimisation and caching

Ask a team how they will cut their model bill and most answer with a cheaper model. It is the last lever on the published list, not the first — and the four above it cost you nothing at all. The ordering is the whole lesson.

A quick note on where this sits. Lesson 20 is about the number you report — cost per successful outcome, gross margin, what you charge. This one is about the levers you actually pull on Monday, and the order to pull them in.

That order is not a matter of taste. Anthropic publish it as a sequence. The logic is structural. Every lever above model selection is free, and model selection is the only one that lowers what your system can do at all.

Interactive · the order is the lesson

Seven levers, and the cheap model is the last one

Read the middle row across. Four of these cost you nothing at all — and most teams start at number seven.

What it buys
Cache reads at 0.1x base input
Fewer tokens in, on every single turn
Fewer turns, and the resends they carry
50% off all usage, stacking with caching
33–75% less cost, depending on workload
Default accuracy at roughly half the cost
Potentially large, potentially negative
What it costs you
Nothing. Quality is identical
Nothing, if you remove only what is unused
Engineering time, not quality
Latency. Nothing else
Measurable accuracy, sometimes very little
Latency on the minority that fail
The intelligence ceiling itself
When it applies
Any workload with a stable prefix
Bloated system prompts, oversized tool results
Agents averaging more turns than the task needs
Evals, backfills, scheduled jobs — never live traffic
After the free levers, per route, against an eval
Outputs you can check automatically
Last. After sweeping effort on what you have
01 · Prompt caching · Free

The largest lever by a wide margin, and it is not close. Anthropic's own measurement puts it at a factor of 2.5 to 3.7 off agent-loop cost, and 83% off one small triage agent's bill — 88% with input trimming added. It changes no output. If you do one thing from this lesson, do this one.

Optimizing for cost and intelligenceAnthropic docs

Caching, and the one rule it follows

Caching is first because it is the largest lever by a wide margin and it changes no output at all. The measured effect on agent loops is a factor of 2.5 to 3.7, and one small triage agent’s bill fell by 83% — 88% once input trimming was added.

Everything about it follows from one rule. Prompt caching is a prefix match, and any change anywhere in the prefix invalidates everything after it. The prompt renders in a fixed order: tools, then system, then messages.

So the design rule is simply stable content first, volatile content last. Get that ordering right and most of the saving arrives for free. Get it wrong and no amount of cache markers will rescue it.

Interactive · what survives what

Three caches, rendered in order, and a change takes out everything after it

The prompt renders as tools, then system, then messages. Pick a change and see how far down the damage goes.

After: change tool_choice
Tools cachesurvives
System cachesurvives
Messages cacherebuilt

Cheap. You keep the tools and system caches, which are usually the large ones, and lose only the messages tail. Safe to vary per request.

Two silent traps worth knowing. A prompt below the per-model minimum cacheable length is simply not cached, and no error is returned. And a cache read refreshes the entry’s timer for free. So requests arriving less than five minutes apart keep a five-minute entry alive indefinitely, and the one-hour TTL buys nothing there except a doubled write price. Choose the TTL by the gap between requests, not by how long the conversation lasts.

cache_layout.py
# Renders as: tools -> system -> messages.
# Put the frozen content first and the volatile content after the breakpoint.

response = client.messages.create(
    model="claude-opus-5",
    max_tokens=4096,
    tools=TOOLS,                 # deterministic order — sort it, never build it per user
    system=[
        {
            "type": "text",
            "text": STABLE_INSTRUCTIONS,   # no timestamps, no request ids, no user names
            "cache_control": {"type": "ephemeral"},
        },
    ],
    messages=messages,
)

u = response.usage
# A cache miss is silent: the request succeeds and only the bill changes.
# Assert on it in staging rather than discovering it in a monthly invoice.
if u.input_tokens > 0 and u.cache_read_input_tokens == 0 and turn > 1:
    raise AssertionError(
        "cache never read — check for a timestamp in the system prompt, "
        "a tool list that varies per request, or a prefix below the model minimum"
    )
The layout is the whole technique. Everything above the breakpoint must be byte-identical between requests, so the per-request variables go below it. The assertion is worth keeping: cache misses are otherwise silent.
Prompt cachingAnthropic docs

The half-price lever nobody switches on

All usage in a batch is charged at 50% of standard API prices, and the batch and caching discounts stack. For work nobody is waiting on this is close to free money.

Your eval runs are the obvious candidate. So are backfills and scheduled jobs. Most batches finish inside an hour — the 24-hour figure people quote is an expiry, not a service level.

Two constraints decide whether it fits. It is single-shot, so a multi-turn tool loop has to be restructured rather than redirected. And it is genuinely asynchronous, so anything with a person waiting stays on the live path.

Batch processingAnthropic docs

Where the trade begins

Everything so far was free. Effort is the first lever that trades accuracy for money, and on most workloads the trade is better than people expect.

On research-style work, low effort cost 1 to 3 points of accuracy for a 33–50% cost cut, and medium matched the default at 70–85% of cost. Long-horizon coding is steeper: medium lost 2 points for half the cost, low lost 8 points for three-quarters.

There is a cleverer version if your outputs are checkable. Run cheap, detect the failures, and re-run only those at higher effort. Measured on coding work that reached the same pass rate for half the cost, counting the wasted cheap attempts. It needs a real failure signal — a test suite, a schema, a validator — so it belongs to teams who did the evaluation work first.

EffortAnthropic docs

Why the cheap model comes last

Model selection is last because it is the only lever that lowers the ceiling on what the system can do. It is also the one where per-token price lists actively mislead.

Price cost per completed task, not per token. Opus 5 matched a more expensive model on a coding benchmark — 91.7% against 91.3%, inside run-to-run noise — at about 60% of its cost. In the other direction, Haiku 4.5 answered benchmark questions at roughly a tenth of Opus 5’s cost per question, at 63% accuracy against 92%.

That second number is the one to think about. A model that fails a third of the time does not cost a tenth as much, because failures become re-runs, escalations and human time. Cheap per token and cheap per outcome are different quantities, and only one of them is on the invoice.

The line worth having ready: per-token price does not predict cost per completed task, and a comparison that uses it is measuring the wrong thing. Newer models can use more tokens for the same text, which makes them look more expensive by construction while being cheaper per finished job.

There is one more hidden cost in routing between models. Caches are model-scoped. A cascade that sends some steps to a cheaper model forfeits cache reuse across the models it routes between. It gives up lever one to buy lever seven, which is the wrong direction.

A loop change, not a pricing change

🇧🇷🇲🇽🇨🇴 Brazil · Mexico · Colombia

Nubank — three tool calls became one

3 → 1
tool calls on the card-delivery path
131m
customers served
4× / 15×
agent and multi-agent token multipliers

Nubank’s card-delivery agent originally made three separate tool calls to answer one question. They replaced them with a single composite tool. No model changed, no price changed, and no accuracy was traded.

This is lever three, and it compounds harder than it looks. Removing a turn removes its model call — but it also removes the resend of the entire transcript that turn would have carried, on that turn and every turn after it. Against published multipliers of roughly four times chat token usage for agents and fifteen for multi-agent systems, the loop is usually where the money actually is. Most teams look at the price list instead.

Building AI agents for 131 million customersNubank engineering

What to pull at your size

Two of the five below are skips at seed. The multi-model cascade is the one teams reach for first, and it stays a skip until there is genuine bulk to hand off.

Interactive · calibrate to your stage

What to actually do about this, at your size

Nearly all guidance on this topic is written for one company size and then read by everyone. Pick yours — the list re-sorts, and what you should deliberately not build drops to the bottom.

  • Prompt caching on the stable prefixNon-negotiable

    A cache breakpoint after the system prompt and tool definitions, with stable content first.

    At this stage · Now design the prompt around it: stable content first, volatile last, so the cache boundary falls somewhere useful.

  • Batch for anything not user-facingDo it

    Evals, backfills and scheduled jobs routed through the Batch API rather than the live path.

    At this stage · Half price on all usage, and it stacks with caching. Eval runs are the obvious first candidate because nobody is waiting on them.

  • A cache-hit-rate alarmCheap version

    An alert when cache_read_input_tokens falls as a share of input tokens.

    At this stage · A weekly glance at the ratio. This is the stage where somebody adds a timestamp to a system prompt and nobody notices for a month.

  • An effort sweep per routeCheap version

    Measuring accuracy and cost at each effort level on your own traffic, route by route.

    At this stage · Once an eval exists, sweep the highest-volume route only. The published research numbers suggest medium often matches the default at 70–85% of cost, but that is their workload, not yours.

  • A multi-model cascadeSkip it

    Routing steps to different models — a cheap worker with a frontier orchestrator, or an advisor pattern.

    At this stage · Still skip. Sweep effort on the model you have first — a stronger model at lower effort often beats a weaker one, and it keeps one cache namespace.

1 of 5 deliberately skipped at this stage. Knowing which controls you are choosing not to build, and being able to say why, is a stronger signal than having built all of them.

What to remember

  1. 1
    The order is the whole thing

    Caching, input trimming, loop hygiene and batching cost you nothing in quality. Effort, selective re-runs and model choice all trade something. Work the free four before touching the other three.

  2. 2
    Caching is a prefix match

    Tools, then system, then messages — a change invalidates its own tier and everything after it. Stable content first, volatile last. A prompt below the per-model minimum silently does not cache and returns no error.

  3. 3
    Batch is half price and stacks

    All usage at 50%, combining with caching. Evals, backfills and scheduled jobs qualify; anything with a person waiting does not.

  4. 4
    Per-token price is the wrong number

    Price cost per completed task. A model at a tenth the cost per question but 63% accuracy against 92% is not a tenth as cheap, because failures become re-runs. And a multi-model cascade forfeits cache reuse, trading your best lever for your worst.

Sources

Every source in this lesson

Primary sources wherever one exists. Where a claim is contested or vendor-reported, the lesson says so at the point it is made.

Read
  • How we built our multi-agent research systemAnthropic

    The published multipliers behind the loop-hygiene lever: agents use roughly four times the tokens of a chat interaction, and multi-agent systems about fifteen times.

  • Building AI agents for 131 million customersNubank engineering

    Their card-delivery agent replaced three separate tool calls with one composite tool. A loop-hygiene change rather than a pricing one, and the kind that compounds because every removed turn also removes the resend of everything before it.

Docs
  • Optimizing for cost and intelligenceAnthropic docs

    The lever order, published as a sequence rather than a list. Also the measured claim this lesson is built on: prompt caching was the largest lever by a wide margin, cutting agent-loop cost by a factor of 2.5 to 3.7 and one small triage agent's bill by 83%, or 88% with input trimming added.

  • Prompt cachingAnthropic docs

    Cache reads are billed at 0.1x base input, writes at 1.25x for the five-minute TTL. There is a per-model minimum cacheable prefix, and a prompt below it is simply not cached — no error is returned, which is why silent cache misses are so common.

  • Batch processingAnthropic docs

    “All usage is charged at 50% of the standard API prices.” Most batches finish in under an hour; the 24-hour figure is an expiry, not a service level. The batch and caching discounts stack.

  • EffortAnthropic docs

    The first lever that trades quality for cost, and the one to sweep before reaching for a cheaper model. Effort is a per-route setting, not a global one.

  • PricingAnthropic docs

    Per-token list prices. Worth reading precisely because the lesson's argument is that these are the least useful numbers in the discussion — they do not predict cost per completed task.

Lesson 20
Serving a GPU fleet
Lesson 22
Multi-agent orchestration