PrepGenAICerts
Courses/Claude Certified Developer – Foundations (CCDV-F) Full Course/5.6 Prompt Caching and the Message Batches API
Domain 5: Model Selection and OptimizationLesson 22 of 32

5.6 Prompt Caching and the Message Batches API

5.6.1 Prompt Caching: Discounting a Stable, Reused Prefix

When many requests share a large, stable prefix — a system prompt, a long reference document, a set of tool definitions — reprocessing that entire prefix at full price on every single call is wasteful, because its content genuinely hasn't changed between calls. Prompt caching solves this: mark the end of the stable prefix with a `cache_control` field of type `"ephemeral"` on the last content block you want cached. That field marks a **breakpoint** — everything up to and including that block is cached as a unit. You can place **up to 4 breakpoints** per request, which matters once a prompt has more than one genuinely stable segment (say, a stable tool-definition block plus a separately stable, longer reference document appended after it).

Breakpoint placement has to respect one structural fact the exam likes to test directly: the API always processes a request in a **fixed order — tools first, then the system prompt, then messages.** A breakpoint placed right after the tool definitions caches the tools alone; a breakpoint placed at the end of the system prompt caches tools AND system together, since both preceded it in that fixed order. There is no way to cache message content "ahead of" the system prompt — messages are always processed after the system prompt regardless of where a breakpoint sits.

The two rates in that structure point in opposite directions, and the exam expects the actual numbers, not just the direction. Cache writes are billed at a premium over the base input-token price: **1.25x for the default 5-minute TTL**, or **2x for the opt-in 1-hour TTL**. Cache reads cost only **0.1x** standard input price — a 90% discount. The economics only pay off through reuse *within the TTL window*: the call that writes the cache pays the premium, and every subsequent call that reads that same cached prefix before it expires pays only 0.1x. A single one-off call that writes a cache and is never read again pays that premium with nothing to offset it — that call costs strictly MORE than the same call would have cost with no caching at all.

OperationPrice relative to normal input tokens
Cache write, 5-minute TTL (default)1.25x — a 25% premium
Cache write, 1-hour TTL (ttl: "1h" on the breakpoint)2x — a 100% premium
Cache read (any TTL, subsequent calls reusing the prefix)0.1x — a 90% discount

Caching pays off through reuse across many calls within the TTL window, not on the first call — a write is always a premium, never a saving.

Worked example: a 2,000-token system prompt is stable and gets reused across 50 calls, all made within a single 5-minute window (each read resets the cache's 5-minute clock, so the cache stays alive throughout a burst like this). Without caching, the cost is 50 calls x 2,000 tokens x 1.0 (base rate) = 100,000 token-units. With caching: one write at 1.25x (2,000 x 1.25 = 2,500 units) plus 49 reads at 0.1x each (49 x 2,000 x 0.1 = 9,800 units), for a total of 12,300 units — roughly **12% of the uncached cost**, an ~8x reduction, driven entirely by the 49 cheap reads absorbing the one write premium.

⚠️

5.6.1 — Exam Trap

A single cached call ALWAYS costs more than the same call with no caching at all — it pays the 1.25x (or 2x) write premium with no read to offset it. Caching is not a discount you get "just by setting the field"; it is a bet that pays off only once a cached prefix is actually re-read within the TTL window. "Cache reads and writes are priced the same" is also false — reads are 0.1x, writes are 1.25x/2x.

5.6.1 — Key Concept

The default cache lifetime is 5 minutes from the LAST READ — every read resets that clock, so a frequently-hit prefix stays alive indefinitely without ever needing to be rewritten. The 1-hour TTL is an explicit opt-in (ttl: "1h" on the breakpoint) at the higher 2x write cost, for workloads with gaps longer than 5 minutes between calls. There is also a minimum-token threshold for caching to apply at all — roughly 1,024 tokens for most current models (this varies by model) — a breakpoint set on a prompt shorter than that threshold simply will not cache, with no error raised.

5.6.2 Cache Checkpointing: Keeping a Growing Prompt Mostly Cached

A single static prefix is the simple case, but plenty of real prompts grow incrementally over a session — an agent loop that keeps appending tool results to a running conversation is the classic example. Naively, you might expect that every new appended token invalidates the entire cache built up so far, forcing a full, expensive reprocessing of the whole growing context on every turn.

Cache checkpointing avoids that. It lets you cache at multiple points along a growing prompt, so that as new content is appended at the end, the earlier, unchanged portions of the prompt stay cached and cheap to reuse — only the newly appended tail needs to be processed at full price. For a long-running agent session, this is the difference between the cache cost climbing back to full price on every single turn versus staying mostly discounted throughout the session's growth.

Cache checkpointing on a growing promptCheckpoint 1cached, cheap to reuseCheckpoint 2cached, cheap to reuseNew tailonly this part at full priceonly the newly appended content needs full-price processing each turn

Cache checkpointing preserves earlier cached segments as a prompt grows, so only the newly appended tail is processed at full price.

5.6.2 — Key Concept

Cache checkpointing caches at multiple points in a growing, incrementally-extended prompt, so a long agent session or similar growing context stays mostly cached as new content is appended, rather than invalidating the whole cache on every extension.

Checkpointing shares the same 4-breakpoint budget

Cache checkpointing isn't a separate feature from the breakpoint mechanism in 5.6.1 — it's the same cache_control / ephemeral breakpoints, placed at more than one point in a growing prompt, still capped at 4 breakpoints per request and still subject to the fixed tools-then-system-then-messages processing order. On a long agent loop, that usually means one breakpoint after the stable system prompt/tools and one or two more further into the accumulated history, leaving the remaining budget for whatever the session grows into next.

5.6.3 Don't Truncate a Stable Prefix Instead of Caching It

A common but avoidable mistake is reaching for truncation as the cost-saving move on a large document or long stable prefix, when caching the full content would have preserved correctness at a similar or better cost profile. Truncating a needed reference document to save tokens trades away information the task may genuinely need, in exchange for a saving that caching could deliver without any loss of content at all.

The decision rule is straightforward: if a large piece of content is stable and will be reused across multiple calls, cache it rather than cutting it down. Truncation is a tool for content that genuinely isn't needed in full, or that has no reuse pattern to cache against — not a default response to "this is taking up a lot of tokens."

Where this shows up on the exam

Watch for a scenario describing a large, reused reference document where the offered "fix" is truncating it. If the document is stable and reused across calls, caching the full document — not truncating it — is the intended answer.

5.6.4 The Message Batches API: A Cost Lever, Not a Latency Lever

The Message Batches API processes a large set of requests asynchronously, completing within a 24-hour window, in exchange for a roughly 50% per-token discount versus standard synchronous pricing. It fits latency-tolerant, high-volume jobs — bulk classification, large-scale content generation, offline evaluation runs — where no individual request needs an immediate, synchronous response.

The defining exam point is what batching trades for that discount: speed. It is slower by design — results arrive asynchronously, potentially hours later — so it reduces cost, not latency. This puts it in a genuinely different category from the other levers in this domain. Prompt caching and right-sizing the model to a smaller tier both reduce cost AND latency. Batching only reduces cost; reaching for it on a latency-sensitive step would be a mismatch, not an optimization.

The exact limits and mechanics matter as much as the discount itself. A single batch call accepts **up to 100,000 requests OR 256 MB of total request size, whichever limit is hit first** — a batch of many small requests can hit the count ceiling well before the size ceiling, and a batch of fewer, larger requests (each carrying a big document, say) can hit the size ceiling long before 100,000 requests. Submitting a batch returns a `batch_id` immediately; the batch itself then runs asynchronously, and your code **polls** for completion — checking the batch's status on some interval until the API reports it has finished, or until the 24-hour window elapses at the latest. Once complete, you retrieve the results.

The detail most likely to trip someone up in practice: **batch results return in ARBITRARY order**, not the order the requests were submitted in. If you submit 500 requests, you cannot assume result #37 in the returned list corresponds to input #37 you sent. The fix is the **`custom_id` field**: set it on each request when you submit the batch, and that same `custom_id` is echoed back on the corresponding result. Matching results back to inputs means keying off `custom_id`, never off list position.

LeverReduces cost?Reduces latency?
Message Batches APIYes (~50% discount)No — slower by design
Prompt cachingYes (cheap cache reads)Yes (shorter time-to-first-token on cache hits)
Smaller / right-sized model (e.g., Haiku)YesYes
Trimming unnecessary context/tokensYesYes (less to process)

Batching is the only lever in this table that reduces cost without also reducing latency — it is explicitly slower by design.

Batching and caching are not competing levers — they compound. A scheduled, non-urgent batch job that reuses the same long system prompt across many requests inside one batch call gets the ~50% batch discount on every request AND the caching discount on the repeated prefix inside each one. Chunking a list and looping over the *synchronous* API, one request at a time, is a common false substitute for this — it produces the same number of individual API calls as the un-chunked version, runs into the exact same rate limits, and captures none of the batch discount. The Message Batches API is a genuinely different submission model (one call, up to 100,000 requests/256 MB, a batch_id, asynchronous completion), not a smaller batch size wrapped around the synchronous endpoint.

⚠️

5.6.4 — Exam Trap

Assuming batching improves latency because it processes "in bulk" is wrong — it is explicitly slower, trading time for a lower per-token price. Don't reach for batching on a latency-sensitive workflow step; caching or a smaller model are the correct levers there.

⚠️

5.6.4 — Exam Trap (limits and ordering)

Two more traps beyond "batching is slower, not faster": (1) a batch call is capped at 100,000 requests OR 256 MB, whichever comes first — not one flat number; and (2) there's no guaranteed correspondence between submission order and the order results come back in, so matching a result to its input requires the custom_id field, never list position.

5.6.5 Put It Together: The Exam Traps for Task Statement 5.6

Task Statement 5.6 questions typically describe a cost or latency problem and ask which lever — caching, checkpointing, batching, or a smaller model — fits, or ask you to distinguish cost levers from latency levers directly.

  • Assuming cache reads and writes are priced the same. ✗ An answer treating caching as uniformly discounted from the first call. ✓ The answer recognizing writes carry a slight premium and reads are the discounted, reuse-driven savings.
  • Truncating a reused stable document to save tokens. ✗ An answer that cuts down a document that will be reused across calls. ✓ The answer that caches the full document instead of truncating it.
  • Expecting batching to reduce latency. ✗ An answer claiming the Message Batches API speeds up response time. ✓ The answer stating batching reduces cost (~50%) at the cost of being slower by design, fitting latency-tolerant jobs only.
  • Confusing cost levers with latency levers generally. ✗ An answer applying a cost-only lever (batching) to a latency-sensitive problem. ✓ The answer matching caching/smaller-model to latency-sensitive problems and batching to cost-only, latency-tolerant ones.

Key Takeaways

  • cache_control caches a large, stable, reused prefix (system prompt, long docs, tool defs) instead of reprocessing it at full price every call.
  • Cache reads are heavily discounted; cache writes cost slightly more than normal input tokens — savings come from reuse, not the first call.
  • Cache checkpointing caches at multiple points in a growing, incrementally-extended prompt so it stays mostly cached as new content is appended.
  • Cache the full stable prefix rather than truncating it to save tokens, when that content will be reused across calls.
  • The Message Batches API gives a roughly 50% per-token discount for asynchronous jobs completed within 24 hours.
  • Batching reduces cost, not latency — it is slower by design, unlike caching or right-sized models, which reduce both.
  • Batching fits latency-tolerant, high-volume workloads where no individual request needs an immediate synchronous response.
  • Cache writes cost 1.25x the base input-token price at the default 5-minute TTL, or 2x at the opt-in 1-hour TTL (ttl: "1h"); cache reads cost 0.1x — a 90% discount.
  • A single, never-reread cached call always costs MORE than the same call with no caching — the write premium has nothing to offset it without at least one subsequent read inside the TTL window.
  • cache_control (type "ephemeral") marks a breakpoint; up to 4 are allowed per request, and the API always processes tools, then system prompt, then messages in that fixed order.
  • The default cache lifetime is 5 minutes from the last read (each read resets the clock); there's also a minimum-token threshold (roughly 1,024 tokens for most current models) below which a breakpoint silently does not cache.
  • The Message Batches API accepts up to 100,000 requests OR 256 MB per batch call, whichever limit is hit first; it returns a batch_id, and you poll for completion.
  • There's no guaranteed relationship between submission order and the order batch results arrive in — rely on the custom_id field on each request to match results back to their original inputs.

Check Your Understanding

Test what you learned in this lesson.

Q1.A system makes a single one-off call using a large system prompt marked with `cache_control`, and the prompt is never reused again. What is the cost outcome?

Q2.An agent session keeps appending new tool results to a growing conversation over many turns. Without cache checkpointing, what would happen on each turn, and what does checkpointing fix?

Q3.A team needs to process 2 million bulk classification requests where results are needed within 24 hours but not immediately. Which lever best fits, and what should they expect?

Q4.A latency-sensitive, real-time feature currently uses a full-price model call. A teammate suggests switching it to the Message Batches API to "save money." What is the issue?

Q5.A team caches a 3,000-token system prompt with `cache_control` but only ever makes ONE call using that prompt before the session ends — no follow-up call ever reads the cache. What is the cost outcome of that single call, compared to not caching at all?

Q6.A request has a set of tool definitions followed by a long system prompt followed by the conversation messages. A single `cache_control` breakpoint is placed on the last block of the system prompt. What does that breakpoint cache?

Q7.A team submits a Message Batches API call with 40,000 requests, each carrying a large document, totaling 300 MB. What happens, and what limit governs a batch call in general?

Q8.A team submits 200 requests in one Message Batches API call and needs to match each result back to the original input that produced it once the batch completes. What should they rely on?

Practice This Lesson

PrepGenAICerts.com is an independent third-party exam-prep platform for the Claude Certified Architect (CCA-F) certification. We are not affiliated with, endorsed by, or acting on behalf of Anthropic PBC.

Note: New premium upgrades are temporarily paused while we resolve an issue with our payment provider. Existing premium members retain full access.