1. Token Economics: What You're Actually Paying For
Every call is billed on tokens in (your prompt, system prompt, any attached documents or images) and tokens out (Claude's response) — input and output are typically priced differently, with output usually costing meaningfully more per token than input. Bigger models cost more per token than smaller ones, which is the whole reason Week 1's Opus/Sonnet/Haiku decision matters financially, not just qualitatively.
response = client.messages.create(...)
print(response.usage.input_tokens) # what the request cost you, in tokens
print(response.usage.output_tokens) # what the response cost you, in tokens
# Multiply each by that model's current per-token price (check the
# Anthropic pricing page — it's the one number in this lesson worth
# looking up fresh rather than memorizing, since pricing evolves).
The concept that doesn't change even as prices do: a large system prompt, a long attached document, or extensive few-shot examples (Week 2) all become part of your input tokens on every single call that includes them — repeating a 2,000- token document across 10,000 calls a day adds up fast, which is exactly the problem caching solves next.
Model prices change over time as new versions ship — always pull current numbers from the Anthropic pricing page for any real cost estimate rather than trusting a number you remember from a while ago.
2. Prompt Caching
If the same large block of context — a system prompt, a long document, a set of few-shot examples — gets reused across many calls, mark it as cacheable. On a cache hit, Claude skips reprocessing that content from scratch, which cuts both cost and latency for every subsequent call that reuses it.
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
system=[
{
"type": "text",
"text": long_reused_instructions, # e.g. a big set of rules/context
"cache_control": {"type": "ephemeral"},
}
],
messages=[{"role": "user", "content": "The actual per-request question"}],
)
The cache has a limited lifetime (it expires after a period of inactivity), so caching pays off specifically for high-repeat workloads — a chatbot reusing the same long system prompt on every incoming message, or a document-analysis pipeline asking many different questions about the same attached document — not for one-off calls that never repeat that context again.
Structure requests so the reused, cacheable part (system prompt, reference document) comes before the part that changes on every call (the actual user question) — this maximizes what can actually be cached rather than invalidating the cache because something upstream of it kept changing.
3. Choosing a Model, With Real Numbers
Week 1 framed the Opus/Sonnet/Haiku decision qualitatively — how hard is the task. Now add the cost dimension: the wrong choice compounds at scale. A task run once barely matters which model you pick; a task run 100,000 times a day makes the wrong tier expensive fast.
# A simple classification task, run at three different volumes:
#
# Run once: tier choice barely matters — seconds and cents either way
# Run 1,000x/day: a pricier tier is still probably fine
# Run 100,000x/day: tier choice is now a real line item — the cheapest
# tier that hits your required accuracy wins decisively
#
# The task didn't change. The volume did. That's the whole decision.
The practical process: don't assume a smaller model "can't handle it" — measure. Run a real sample of your actual task through the cheaper tier first, check the accuracy against what you actually need, and only reach for a pricier tier if the cheaper one genuinely falls short on real examples, not out of caution alone.
Route the easy majority of a workload to a cheap, fast tier, and escalate only the genuinely hard or uncertain cases to a more capable model (Claude itself can even help decide which bucket a case falls into) — you don't have to pick one tier for an entire workload.
4. The Batch API for Bulk Work
For large workloads that don't need an immediate response — classifying 50,000 support tickets overnight, generating summaries for a backlog of documents — the batch API processes requests asynchronously at a meaningful cost discount compared to the standard API, since there's no real-time latency requirement to satisfy.
# 1. Submit a large list of individual requests as one batch job
# 2. The batch processes over some time window (not instantaneous)
# 3. Poll for completion, then retrieve all results together
#
# This is exactly Week 1's "high-volume, low-complexity, Haiku-shaped"
# workload — batch is the delivery mechanism for running it cheaply at
# scale, once you don't need any single result back immediately.
The tradeoff is explicit: you give up immediacy in exchange for lower cost. That makes the batch API the wrong choice for anything user-facing in real time (a chat response, a live tool call) and the right choice for anything that's fundamentally a backend job.
Weeks 6–9 covered the full arc: making a call, giving Claude tools, sending images and documents, and now running all of it efficiently at scale. Weeks 10–12 shift to Claude Code, which is effectively this same API wrapped in an agentic terminal experience purpose-built for working in a codebase.
5. Hands-on Exercise
Measure real cost, prove caching works, and design a workload's model strategy
Turn the concepts into numbers from your own API usage.
Part 1 — Measure a real call's cost:
- Make a call with a reasonably long prompt (500+ words of context) and print
usage.input_tokensandusage.output_tokens. - Look up current per-token pricing for your model and calculate the actual cost of that one call.
Part 2 — Prove caching changes something:
- Pick a large, reusable block of context (a long document or a big system prompt) and mark it cacheable.
- Make the same call twice in quick succession with different user questions but the same cached content.
- Compare the usage/cache fields in each response to confirm the second call registered a cache hit.
Look for cache-related fields in the response's usage object (e.g. cache creation vs. cache read token counts) — that's your direct evidence the cache actually did something on the second call.
Part 3 — Design a real workload's strategy:
- Pick a plausible real workload (classify incoming emails, summarize daily reports, answer FAQ questions from docs).
- Decide: which model tier, whether caching applies, and whether it belongs on the standard API or the batch API — write two sentences justifying each choice.
6. Knowledge Check
Four quick questions. Expand each to check your answer.
Q1
Why does a large, repeated system prompt or document matter more at scale than for a single call?
Why does a large, repeated system prompt or document matter more at scale than for a single call?
That content becomes part of the input tokens billed on every single call that includes it. For a one-off call the cost is trivial, but repeated across thousands or millions of calls, the same reused context multiplies into a real, recurring cost.
Q2
What kind of workload actually benefits from prompt caching, and what kind doesn't?
What kind of workload actually benefits from prompt caching, and what kind doesn't?
High-repeat workloads that reuse the same large context across many calls (a chatbot's system prompt, repeated questions about one document) benefit — the reused content is only fully processed once. A one-off call that never reuses that context again gets no benefit.
Q3
What's the recommended process for choosing a model tier, rather than defaulting to the most capable one out of caution?
What's the recommended process for choosing a model tier, rather than defaulting to the most capable one out of caution?
Measure: run a real sample of the actual task through the cheaper tier and check its accuracy against what's actually needed. Only escalate to a pricier tier if the cheaper one genuinely falls short on real examples — not by assuming it can't handle it.
Q4
When is the batch API the right choice, and when is it the wrong one?
When is the batch API the right choice, and when is it the wrong one?
Right for large, non-real-time backend workloads (bulk classification, overnight processing) where the cost discount is worth trading away immediacy. Wrong for anything user-facing in real time, like a live chat response or an interactive tool call, where an immediate result is required.