CertSafari
    Anthropic Claude Certified Architect – Professional (CCAR-P)· Lessons

    Domain 4 · Lesson 24/38

    Optimizing Claude cost and latency: free wins, batching and budgets

    Optimize token usage, latency, and cost-performance trade-offs

    22 min read
    2.67% of exam
    7 sources
    Published 19 Oct 2026
    Docs as of 14 Oct 2026

    What you will be able to do

    • Tell apart levers that cut cost without touching quality from levers that trade quality away, and apply them in that order
    • Explain why prompt caching dominates agent-loop cost and choose the 5-minute or 1-hour cache duration from a workload's pauses
    • Trim per-call tokens through prompt hygiene, input trimming and context lifecycle levers, and know when those levers fail to pay
    • Route non-urgent work to the Message Batches API and know what it gives up
    • Bound spend with max_tokens, session and task budgets, and a low-effort-then-re-run policy

    Key concept

    Free wins versus trade-offs — Some cost levers lower spend without changing output quality (caching, token hygiene, batching), while others buy savings with quality (smaller model, lower effort, tight caps). Use up the free levers first, then spend quality only where evals show you can afford it.

    1.Two kinds of cost levers

    Every cost lever on the Claude Platform falls into one of two groups, and the groups should be pulled in order. The first group, the free wins, moves a workload closer to the cost-to-intelligence frontier: you pay less for the same output. The second group moves the workload along that frontier, so each dollar saved costs some quality. Free wins include prompt caching, token hygiene, a prompt audit against the model you are actually running, batch processing at 50% off for work that can wait up to 24 hours, and workspace spend limits as a backstop. The trade-offs are model choice, effort, output caps and session budgets, an elapsed-time clock, and multi-model architectures.

    The two groups of levers and what each costs you
    LeverGroupWhat you give up
    Prompt cachingFree winNothing in quality; a cache write costs 1.25x input for new content
    Token hygieneFree winNothing in quality, though one context-lifecycle lever cost more than it saved in a measured run
    Message BatchesFree winLatency: results can take up to 24 hours
    Workspace spend limitFree win (backstop)Nothing; it caps runaway spend
    Smaller model or lower effortTrade-offSome capability
    Output caps, session budgets, elapsed-time clockTrade-offRuns that hit the limit may end unfinished or score lower

    The order matters because the two groups fail differently. A free win that doesn't pay off leaves quality where it was. A trade-off that goes too far shows up as lower task success, and you only find out through evals. So the default advice for any workload on any model is to turn on caching and trim unneeded tokens first. Only when costs are still too high, with quality fine, do you try lower effort or a smaller model. All of Anthropic's figures here are internal and directional, so check every lever against your own workload.

    Checkpoint 1 of 10· Match them up

    Match each cost lever to what you give up when you use it

    Tap a term, then the definition that fits it.

    Sources1

    2.Why caching dominates agent-loop cost

    Agent loops are expensive because every turn resends the entire conversation so far: system prompt, tool definitions and every prior turn. A 40-turn task sends its first turn 40 times, so cost grows with roughly the square of the number of turns. Caching doesn't stop the resending. It makes each resend cheap: the cached prefix is billed at the cache-read rate, and only new content pays the 1.25x write rate. On most models a read costs a tenth of the input price, on Claude Opus 5.5 and Claude Sonnet 5.5 a twentieth, and on Claude Fable 5.1 and Claude Mythos 5.1 a fortieth. Cached prefixes are also processed faster, so the same change cuts latency too. For the mechanics of stable prefixes, automatic caching and breakpoints, see Prompt caching: stable prefix, automatic caching and breakpoints.

    Average token cost per task without caching, relative to the same runs with caching
    WorkloadModelWithout caching
    SWE-bench ProClaude Opus 5.53.3 times the cost
    SWE-bench ProClaude Sonnet 5.53.1 times the cost
    Claude Managed Agents task set (short sessions)Claude Haiku 5.51.7 times the cost
    Small bug-report triage agentClaude Sonnet 5.57.3 times the cost

    The savings depend on turn count, because shorter loops re-read less, which is why the short Haiku sessions save the least. Your benchmark is the cache-read share of input. Over a full day of real traffic, agent loops read a median 84% of their input from the cache, and a well-built loop deep in a task pays full price on under 1% of its input. Below about 80%, something is breaking the cache.

    The thing that gets cached is a prefix, and it has to match byte for byte. Take a support bot that sends a 30,000-token product manual in its system prompt ahead of a short, different question on every request, with requests 30 to 90 seconds apart. Putting a cache breakpoint on the manual block means each request reads those 30,000 tokens from cache instead of processing them again. That cuts both cost and latency, and the gaps between requests are well inside the default 5-minute lifetime. Other changes don't help. Moving the manual after the question puts changing content in front of it, so no request shares a prefix. Rotating ten manual fragments splits the traffic across ten prefixes. Lowering max_tokens shortens output but leaves all 30,000 input tokens to be processed on every call.

    An explicit breakpoint on the system prompt, combined with automatic caching for the conversationjson
    {
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "cache_control": { "type": "ephemeral" },
      "system": [
        {
          "type": "text",
          "text": "You are a helpful assistant.",
          "cache_control": { "type": "ephemeral" }
        }
      ],
      "messages": [{ "role": "user", "content": "What are the key terms?" }]
    }

    Checkpoint 2 of 10· Check yourself

    A day of logs from your coding agent shows that only 62% of its input tokens are read from the prompt cache. Turns arrive a few seconds apart. What should you conclude?

    Checkpoint 3 of 10· Exam question

    A support-bot application sends the same 30,000-token product manual as part of the system prompt on every request, followed by a short unique user question. Requests arrive roughly every 30-90 seconds throughout the day. Which change most directly reduces both cost and latency for this workload without changing the model or the manual content?

    Sources12

    3.Choosing the 5-minute or 1-hour cache from the pauses

    The cache duration is a pricing choice, and the right answer comes from the gaps between consecutive requests, not from how long a session lasts. The default lifetime is 5 minutes, and it is refreshed at no extra cost whenever the cache is read. The 1-hour duration costs 2x the input price to write instead of 1.25x. A miss on either duration bills the whole prefix at the write price, not the read price. So the 1-hour cache earns its higher write price only when pauses long enough to expire a 5-minute entry come up often enough.

    Requesting the 1-hour duration with automatic cachingjson
    { "cache_control": { "type": "ephemeral", "ttl": "1h" } }
    Picking the duration from the gaps between requests
    Your gaps between requestsModelUse
    Turns arrive seconds apartAny5-minute default
    About 1 gap in 20 or more falls between 5 minutes and an hour, and few run over an hourAny1-hour duration
    About 60% or more of pauses longer than 5 minutes also run past an hourAny5-minute default
    Only 1 or 2 gaps in 20 fall between 5 minutes and an hour, none over about half an hourClaude Opus 5.5 and Claude Sonnet 5.55-minute cache kept warm
    A pause comes before every turnClaude Opus 5.5 and Claude Sonnet 5.51-hour duration
    Pauses run for minutesClaude Fable 5.15-minute cache kept warm
    Pauses run toward an hourClaude Fable 5.11-hour duration

    The 1-hour duration is not a free upgrade. With turns seconds apart, the default cost about 19% less than the 1-hour setting on Claude Sonnet 5.5. When gaps over an hour are common, both durations expire, and the 1-hour setting then rewrites the prefix at its higher write price. The 1-in-20 rule leaves a margin over the measured break-even of about 1 turn in 30. At 1 turn in 10, staying on the 5-minute setting cost 54% more.

    Keeping the 5-minute cache warm is the alternative to buying the hour. Take the previous request, set max_tokens to 0, drop stream, and change nothing in the prefix. Resend it with the original headers, including any anthropic-beta header. Send it within 4 minutes of the previous request's start and every 4 minutes after that, because the lifetime counts from when a request starts. It returns no output and costs little more than a cache read. A max_tokens: 0 request is rejected when it sets thinking.type: "enabled", structured outputs, a forced tool choice, or the top-level compaction parameter. For those workloads, buy the 1-hour duration instead.

    Checkpoint 4 of 10· Check yourself

    An overnight coding agent on Claude Sonnet 5.5 runs for three hours per task, with each turn sent a few seconds after the last one finishes. A teammate wants to switch it to the 1-hour cache because the sessions last far longer than 5 minutes. What should you do?

    Sources12

    4.Token hygiene: trimming what each call carries

    Token hygiene means cutting tokens the task doesn't need from every call: redundant instructions, verbose tool output, and history that no longer matters. The prompt is the first place to look. Say what you mean concisely and drop unnecessary detail and repetition, but keep in mind that Claude knows nothing about your use case and won't fill gaps you leave in unclear instructions. On output, ask Claude directly to be concise. Fewer tokens processed and generated also means a faster response. A prompt audit against the model you are running belongs here too: instructions written for an older model can carry weight the current one doesn't need.

    Input trimming covers bulky inputs such as images and tool definitions. In a measured triage job, resizing images and deferring tool definitions with tool search took 26% off the cost of a 20-issue run and 21% off a longer run, on top of caching. Tool output is usually the largest bulk in a long agent session.

    Long agent sessions also need lifecycle levers, because history keeps growing even after its tool results stop being useful. Three work together:

    • Context editing clears old tool results once the prompt passes a token threshold, keeping only recent tool uses. In one measured configuration it cleared at least 2,000 tokens once the prompt passed 20,000, keeping the three most recent tool uses.
    • Compaction acts once input reaches a set size (50,000 input tokens on one measured job). It shrinks earlier history so the session can go on without hitting the context window.
    • The memory tool writes state that must survive, such as learned patterns or progress, to durable storage, so clearing old context doesn't lose it.

    Two levers that sound similar don't address a filling context window. Lowering effort cuts the tokens of each response and makes tool calls fewer and terser. But the session still carries every earlier turn and tool result, so the window keeps filling. Raising effort to max removes the limit on token spending. The Message Batches API runs each request on its own as an asynchronous job, which can't carry a live agent session that needs one turn's result before it can take the next.

    Checkpoint 5 of 10· Check yourself

    Your team runs long agent sessions with prompt caching on and wants to enable context editing to clear old tool results. One engineer says it is token hygiene, so it can only lower the bill. What is the right approach?

    Checkpoint 6 of 10· Exam question

    An agentic coding assistant runs long sessions that accumulate hundreds of tool calls, and the conversation regularly approaches the model's context window limit before the task is finished. Engineers want strategies that let the session continue productively without losing critical state. Which approaches address this goal?(Select 3)

    0 of 3 selected

    Sources3145

    5.Message Batches for work that can wait

    The Message Batches API halves the price of any workload where nobody is waiting on the answer. You submit many Messages requests together, each with its own custom_id and a standard params object. The system processes them asynchronously, and you poll for results. All usage is charged at 50% of standard prices. Most batches finish within an hour, but results are guaranteed only once every request is done or 24 hours have passed. The discount is paid for in latency.

    Consider a nightly job that scores 50,000 archived support tickets against a rubric, takes six hours on synchronous calls, and has no user waiting. Batching is the direct fix: same model, same prompts, half the price. A single batch holds up to 100,000 requests or 256 MB. Raising effort to max or turning on extended thinking would add tokens rather than cut them. Switching to the 1-hour cache only pays when there are pauses between 5 minutes and an hour, and it doesn't cut the price of every request.

    What batching changes about a request
    AspectBehaviour in a batch
    Price50% of standard API prices for all usage
    CompletionMost within 1 hour; batches expire if not done within 24 hours
    Results retentionAvailable for 29 days after creation
    stream: trueRejected: results come back as a single file
    speed (Fast mode)Rejected: it tunes synchronous latency
    max_tokensMust be at least 1; max_tokens: 0 cache pre-warming is not supported
    Spend limitMay go slightly over the Workspace's configured limit

    Good fits include large-scale evaluations, content moderation, data analysis and bulk content generation. Bad fits are anything interactive. A user-facing chat needs the opposite: streaming, which shows output as it arrives and makes the application feel more responsive, and which a batch can't do.

    Checkpoint 7 of 10· Match them up

    You are moving a synchronous Messages workload onto the Message Batches API. Pair each setting or property with how it behaves inside a batch.

    Tap a term, then the definition that fits it.

    Checkpoint 8 of 10· Exam question

    A team runs a nightly job that scores 50,000 archived support tickets against a rubric. The job has no interactive user waiting on results and currently completes in about six hours using standard synchronous API calls, at a cost the finance team has flagged as too high. What should the team do to reduce cost for this specific workload?

    Sources63

    6.Trade-off levers: effort and model tier

    Once the free wins are used up, lowering effort is the first trade-off to try when costs are too high and quality is fine. Effort sets how many tokens the model spends on its reply, its thinking and its tool calls; the full picture is in Effort: the accuracy-latency dial within one model. As a cost lever it saves a lot and costs real quality. At low, Claude Opus 5.5's typical task took 84% less time than at medium on DRACO, and scored 13.3 points lower. If quality drops after you lower effort, put it back before you look for another fix.

    Moving steps to a smaller model is the other trade-off; how to design tiered and multi-model systems is in Model tiering and multi-model designs. As an optimisation, measure it as cost per completed task, not cost per token. A cheaper model that fails more often and needs retries or fixes can cost more per finished task. For high-volume work whose outputs you can check, try Claude Haiku 5.5 first. If you aren't on the latest model, upgrading is close to free: in Anthropic's measurements each newer model solved at least as many tasks as the one before, usually for less per solved task.

    Checkpoint 9 of 10· Match them up

    The free wins are already in place. Pair each situation with the trade-off move the lesson recommends for it.

    Tap a term, then the definition that fits it.

    Sources1

    7.Bounding spend: max_tokens, budgets and re-running failures

    max_tokens is a hard limit on total output, thinking plus response text, so it bounds the worst case. It doesn't set a target. Setting it too low is the common mistake: attempts end with stop_reason: max_tokens and the work is lost. The fix is to raise it to 64,000. In Anthropic's tests only 2 of about 14,000 turns went past that, and cost per solved task stayed about the same, because a model that doesn't need the room doesn't use it.

    Agent loops have a different risk: most runs are cheap, and a few are very expensive. Bound those with a Claude Managed Agents session budget, plus a workspace spend limit as the account-wide backstop. On newer models you can also give the model an explicit budget through task budgets, which are in beta. When the clock matters more than the bill, tell the model that time matters and show it the elapsed time. In Anthropic's tests that cut run time by 7% to 47% for a few points of score.

    When you can check an outcome with tests or a verifier, the cheapest point on the effort curve isn't any fixed setting. Run everything cheaply and spend more only on the attempts that failed. On Claude Opus 5.5's SWE-bench Pro runs, 13% of tasks failed at low. Re-running those at high gave a slightly higher pass rate than running everything at high, for a little over half the cost. Adopt the policy for the savings, not the gain in pass rate: re-running the failures of an all-high run scores about the same.

    Re-run policies on the Claude Opus 5.5 SWE-bench Pro subset (re-run costs include the failed cheap attempts)
    PolicyTasks solvedCost per task
    low, failures re-run at highAbout 97%About $0.17 USD
    medium, failures re-run at highAbout 97%About $0.24 USD
    Everything at high95.3%$0.29 USD

    Checkpoint 10 of 10· Check yourself

    Many of your coding agent's attempts end with stop_reason: max_tokens, and the work in them is lost. A colleague won't raise the limit, saying a higher max_tokens will make every request cost more. What should you do?

    Sources517

    Sources

    (7)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Free wins cut spend without touching quality”
      ↩︎ Two kinds of cost levers
      “Tradeoffs exchange cost for intelligence: model choice, effort, output caps and session budgets, an elapsed-time clock, and multi-model architectures.”
      ↩︎ Two kinds of cost levers
      “Turn on prompt caching and trim unneeded tokens; both are free”
      ↩︎ Two kinds of cost levers
      “A 40-turn task sends its first turn 40 times, so task cost grows with roughly the square of turn count.”
      ↩︎ Why caching dominates agent-loop cost
      “Below about 80%, look for something breaking the cache”
      ↩︎ Why caching dominates agent-loop cost
      “Do not change a byte of the prefix.”
      ↩︎ Why caching dominates agent-loop cost
      “A miss on either duration bills the whole prefix at the write price instead of the read price.”
      ↩︎ Choosing the 5-minute or 1-hour cache from the pauses
      “Send it within 4 minutes of the previous request's start, and every 4 minutes after that.”
      ↩︎ Choosing the 5-minute or 1-hour cache from the pauses
      “input trimming took 26% off the first and 21% off the second”
      ↩︎ Token hygiene: trimming what each call carries
      “keeping the three most recent tool uses”
      ↩︎ Token hygiene: trimming what each call carries
      “compaction triggered at 50,000 input tokens on the 20-issue job”
      ↩︎ Token hygiene: trimming what each call carries
      “typical task took 84% less time than at medium”
      ↩︎ Trade-off levers: effort and model tier
      “Compare on cost per completed task, not per token”
      ↩︎ Trade-off levers: effort and model tier
      “If you lowered effort, restore it; otherwise try the next tier up at its default effort”
      ↩︎ Trade-off levers: effort and model tier
      “in Anthropic's tests only 2 of about 14,000 turns were longer, and cost per solved task stayed about the same”
      ↩︎ Bounding spend: max_tokens, budgets and re-running failures
      “Set a Claude Managed Agents session budget and a workspace spend limit”
      ↩︎ Bounding spend: max_tokens, budgets and re-running failures
      “7% to 47% less time in Anthropic's tests, for a few points of score”
      ↩︎ Bounding spend: max_tokens, budgets and re-running failures
      “Use this policy for the saving, not the lift.”
      ↩︎ Bounding spend: max_tokens, budgets and re-running failures
      “Free wins cut spend without touching quality”
      ↩︎ Key concept
      “The 1-hour duration costs more to write (2x the input price instead of 1.25x).”
      ↩︎ Exam trap 1
      “context editing, a token-hygiene lever, cost more than it saved in the run measured in this section”
      ↩︎ Exam trap 3
      “in Anthropic's tests only 2 of about 14,000 turns were longer, and cost per solved task stayed about the same”
      ↩︎ Exam trap 4
      “batch processing trades latency for its discount”
      ↩︎ Exam trap 5
      “In Anthropic's measurements, prompt caching was usually the largest lever.”
      ↩︎ Prediction
      “No pauses: the default cost about 19% less than the 1-hour setting on Claude Sonnet 5.5”
      ↩︎ Checkpoint
      “context editing, a token-hygiene lever, cost more than it saved in the run measured in this section.”
      ↩︎ Checkpoint
      “run every task at a low setting and re-run only the failures at a higher one”
      ↩︎ Prediction
      “Raise max_tokens to 64,000: in Anthropic's tests only 2 of about 14,000 turns were longer, and cost per solved task stayed about the same”
      ↩︎ Checkpoint
    2. 2.
      “If found, it uses the cached version, reducing processing time and costs.”
      ↩︎ Why caching dominates agent-loop cost
      “The cache is refreshed for no additional cost each time the cached content is used.”
      ↩︎ Choosing the 5-minute or 1-hour cache from the pauses
    3. 3.
      “Avoid unnecessary details or redundant information”
      ↩︎ Token hygiene: trimming what each call carries
      “This can significantly improve the perceived responsiveness of your application”
      ↩︎ Message Batches for work that can wait
    4. 5.
      “Lower effort also means fewer and terser tool calls.”
      ↩︎ Token hygiene: trimming what each call carries
      “It's a hard limit on total output (thinking plus response text).”
      ↩︎ Bounding spend: max_tokens, budgets and re-running failures
      “Lower effort also means fewer and terser tool calls.”
      ↩︎ Exam trap 2
    5. 6.
      “All usage is charged at 50% of the standard API prices.”
      ↩︎ Message Batches for work that can wait
      “Batches expire if processing does not complete within 24 hours.”
      ↩︎ Message Batches for work that can wait
      “Each batched request must have max_tokens of at least 1.”
      ↩︎ Message Batches for work that can wait
      “stream: true | Batch results come back as a single file, not a stream.”
      ↩︎ Checkpoint
    6. 7.
      “you can give the model an explicit budget with task budgets, which are in beta”
      ↩︎ Bounding spend: max_tokens, budgets and re-running failures

    Ready to test yourself?

    Practise the 12 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.