◉CLAUDE LABJP
●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…
Articles/API & SDK
⬡ API & SDK/2026-05-29Advanced

Splitting Claude API prompt cache into 5m and 1h tiers — separate TTLs cut cost and stabilize ops

Anthropic's cache_control supports two TTLs: 5 minutes and 1 hour. Splitting them into a two-tier layout — 1h for static system/tools, 5m for variable few-shot — meaningfully changed both my costs and my on-call life. Here's the design with the numbers I observed.

claude-api83prompt-caching15cache-controlttlcost-optimization31production111

✦ Premium Article

The Messages API in the Anthropic SDK exposes a cache_control field that lets you ask the server to cache the prefix of a long prompt. I run Claude Lab as part of Dolice Labs (four sites I operate in parallel) and a handful of iOS / Android apps I have been shipping as an indie developer since 2014 (cumulative downloads passed 50 million along the way). Across all of that, the single biggest lever I have found for API cost is not "do you cache or not" but "how many TTLs do you use."

cache_control supports two TTLs: the default 5-minute ephemeral cache, and a 1-hour cache via ttl: "1h". I used to keep everything on 5m and assume that was fine. Six months ago I read the invoices line by line and realized I was leaving a lot on the table. The winning layout turned out to be 1h for static layers (system + tools) and 5m for variable layers (few-shot, RAG slices). This article is the engineering record of that change, with the actual numbers I saw.

Why a single TTL underperforms

My first prompt-cache layout looked like this:

# Before: a single 5m TTL for everything cacheable
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=2048,
    system=[
        {
            "type": "text",
            "text": SYSTEM_PROMPT,  # ~4,500 tokens
            "cache_control": {"type": "ephemeral"},  # 5m
        }
    ],
    tools=TOOLS,        # ~1,200 tokens
    messages=[
        {"role": "user", "content": user_text},
    ],
)

Cache hits started appearing in usage.cache_read_input_tokens, so it looked like things were working. Two real problems took weeks of logs to surface.

First, every time traffic went quiet for more than five minutes — which happened a lot at night and on weekends — the full 4,500-token system prompt was re-written and re-billed at the write rate. The write rate is 1.25x the normal input rate for 5m TTL, so dozens of cold-starts per day quietly ate most of my cache savings.

Second, when I tried to add a variable few-shot block at the end of the prompt, my fixed prefix kept getting invalidated. That was my own misunderstanding of where to put the breakpoint, but the two-tier layout described below removes the temptation entirely.

When 1h TTL is actually worth it

Passing ttl: "1h" extends the cache window to one hour, but the write cost roughly doubles versus the 5m option. If you apply 1h indiscriminately, your bill goes up, not down.

The rule I use is simple:

write-cost increase  <  hit savings
↓
mean inter-request gap  <  1h, with no extended idle windows
↓
1h TTL is worth it

For variable content — per-user few-shot, just-fetched RAG passages — 1h is meaningless. That content does not survive an hour and does not need to. Keep those layers on 5m.

In my workloads, the layers that actually benefit from 1h are:

  • The long system prompt (persona, output format, safety rails)
  • The tools JSON Schema block, especially when I have five or more tools defined
  • A shared knowledge "core" common across all users

Everything user-specific or daily-rotating stays on 5m.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦A concrete two-tier layout: 1h TTL for system/tools, 5m TTL for variable few-shot — with code
✦How to read cache_read_input_tokens vs. cache_creation_input_tokens to decide whether your TTL choice is correct
✦Numbers from my production workload (multiple iOS/Android apps and the four Dolice Labs sites) where this layout reduced input-token cost by about 42%
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ API & SDK2026-04-26
How I Cut My Claude API Bill in Half With Prompt Caching
Done right, Anthropic's prompt caching can roughly halve your monthly API spend on workloads with long, repeated system prompts. Here is the design playbook I use after six months in production, including the arithmetic that links hit rate to the bill and the break-even points (about 22% on the 5-minute TTL, 53% on the 1-hour TTL).
⬡ API & SDK2026-09-07
A 75% cheaper cache read moved one bill by 29% and another by 2.8%
Fable 5.1 and Mythos 5.1 changed the cache read multiplier from 0.1 to 0.025. Here is how to estimate your own saving from your token mix, and how to fix code that hard-codes the multiplier.
⬡ API & SDK2026-05-05
The Real Cost of Claude API Extended Thinking in Production — ROI Data by Task Type
Three months of measured cost, quality, and speed data for Extended Thinking across five task categories. Learn exactly when extended thinking is worth it—and when it's not.