GrepBoard/Manuals
609 manuals ·

Claude Prompt Caching: 5-Minute or 1-Hour TTL?

·Tested on Python 3.13.18 (Docker python:3.13-slim) · Claude API Prompt caching and Pricing docs · 2026-12·Test scope ↓·6 steps

Compare 5-minute and 1-hour prompt cache costs by request interval, including models with other read multipliers, the expiry edge and burst traffic.

When the same long prompt is sent again every few minutes or every few dozen minutes, the cache_control TTL decides the bill: 5 minutes (the default) or 1 hour ("ttl": "1h"). The numbers below use the multipliers from the official docs (checked 2026-12-02 KST) and cover only the input cost of the cached prefix. Output tokens, input outside the cache, and modifiers such as batch or data residency are left out, and no other vendor's cache is compared.

[1] Check the multipliers first. The Prompt caching page lists 1.25x for a 5-minute write, 2x for a 1-hour write and 0.1x for a read. The read multiplier differs by model. The table footnotes and the Pricing page say:

ModelRead multiplierExample: base input / 5m write / 1h write / read (USD per MTok)
Claude Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.10.025xFable 5.2: 8 / 10 / 16 / 0.20
Claude Opus 5.5, Sonnet 5.50.05xSonnet 5.5: 2 / 2.50 / 4 / 0.10
Every other model0.1xSonnet 5: 2 / 2.50 / 4 / 0.20

Sonnet 5 and Sonnet 5.5 share a base input price but differ twofold on reads. For Claude Haiku 5.5 the docs price a request by prompt length (over 100,000 tokens pays higher rates), and cache reads and writes count toward that length. Write multipliers are 1.25x and 2x for every model in the table.

[2] Confirm the behavior the calculation relies on in the docs.

  • A cache read restarts the lifetime at no extra charge. The default lifetime is 5 minutes.
  • The lifetime is measured from the start of the request that wrote or read the entry. If a response streams for 4 minutes, the next request that reuses the prefix must start within about 1 minute of the response completing.
  • Reading a 5-minute entry restarts its 5-minute lifetime even if the request now sets "ttl": "1h". When one request mixes TTLs, 1-hour entries must come before 5-minute entries.
  • With parallel requests, the entry only exists once the first response starts. Wait for it if you need hits.
  • The minimum cacheable length on the Claude API is 512 tokens (the Fable and Mythos 5.x models, Opus 5.5, Opus 5, Sonnet 5.5, Haiku 5.5), 1,024 (Opus 4.8, Sonnet 5, Sonnet 4.6 and others), 2,048 (Mythos Preview, Opus 4.7) or 4,096 (Opus 4.6, Opus 4.5, Haiku 4.5). Amazon Bedrock (bedrock-mantle) has its own documentation. A shorter prompt is processed without caching and returns no error; both cache_creation_input_tokens and cache_read_input_tokens are 0.

The TTL goes on cache_control:

request.json
"cache_control": { "type": "ephemeral", "ttl": "1h" }

[3] Calculate cost from a list of request times. Save this as ttl.py; it uses only the standard library. Give it the read multiplier and the request start times in seconds, and it prices no cache, 5 minutes and 1 hour in units where sending the cached prefix once at the plain price = 1.0. A request is a read if the previous request started less than the TTL ago, and a write if it started longer ago. The first request is always a write.

ttl.py
import mathimport sys if len(sys.argv) != 3:    sys.exit("usage: ttl.py READ_MULT T1,T2,...")try:    read = float(sys.argv[1])                          # 0.1, 0.05 or 0.025    times = [float(x) for x in sys.argv[2].split(",")]  # request start, secondsexcept ValueError as e:    sys.exit("error: %s" % e)gaps = [b - a for a, b in zip(times, times[1:])]if not all(math.isfinite(x) and x >= 0 for x in [read] + times):    sys.exit("error: values must be finite and not negative")if any(g <= 0 for g in gaps):    sys.exit("error: times must increase (parallel requests are not modeled)") print("none cost=%.4f" % len(times))undecided = Falsefor name, write, ttl in (("5m", 1.25, 300), ("1h", 2.0, 3600)):    if any(abs(g - ttl) < 1e-6 for g in gaps):        print("%s   undecided: a gap equals the TTL (%d s)" % (name, ttl))        undecided = True        continue    hits = sum(g < ttl for g in gaps)    misses = len(times) - hits    print("%s   cost=%.4f hits=%d misses=%d" % (name, misses * write + hits * read, hits, misses))sys.exit(3 if undecided else 0)

First, five requests 4 minutes apart at a read multiplier of 0.1:

console
$ python3 ttl.py 0.1 0,240,480,720,960
output
none cost=5.00005m   cost=1.6500 hits=4 misses=11h   cost=2.4000 hits=4 misses=1

By hand: 5 minutes is one write 1.25 plus 4 reads at 0.1 = 1.65, and 1 hour is 2 + 0.4 = 2.4, which matches the script. More patterns at a read multiplier of 0.1:

Request patternNo cache5 min1 hour
1 request1.001.252.00
3 requests 2 hours apart (all misses)3.003.756.00
5 requests 4 minutes apart5.001.652.40
5 requests 10 minutes apart5.006.252.40
2 requests 50 minutes apart2.002.502.10
3 requests 50 minutes apart3.003.752.20
5 requests 70 minutes apart5.006.2510.00
10 requests 30 s apart, 2 h rest, 10 more20.004.305.80
the same bursts, 20 min rest20.004.303.90

What the table shows:

  • With gaps under 5 minutes (4 minutes), the 5-minute cache is cheaper. The 1-hour cache keeps hitting too, but its write costs 2x.
  • With gaps between 5 minutes and 1 hour (10 and 50 minutes), the 5-minute cache rewrites every time and costs more than no cache (6.25 vs 5.00). The 1-hour cache beats no cache in the rows with 3 or more requests; with 2 requests it is slightly worse (2.10 vs 2.00). That agrees with the Pricing page, which says the 1-hour cache pays off after two reads.
  • With gaps over 1 hour (70 minutes), both rewrite every time and both cost more than no cache. Leave caching off.
  • For burst-then-rest traffic the length of the rest decides. After 2 hours both rewrite, so 5 minutes is cheaper (4.30 vs 5.80). After 20 minutes the 5-minute entry is gone and the 1-hour entry survives, so 1 hour is cheaper (3.90 vs 4.30). A different burst length changes these numbers.

For a model with another read multiplier, change the first argument. Here is the same 4-minute pattern on Sonnet 5.5 (0.05x):

console
$ python3 ttl.py 0.05 0,240,480,720,960
output
none cost=5.00005m   cost=1.4500 hits=4 misses=11h   cost=2.2000 hits=4 misses=1

To get a dollar figure, multiply by cached tokens × base input price ÷ 1,000,000. With 50,000 tokens on Sonnet 5.5 ($2/MTok), 1.0 is $0.10, so no cache costs $0.50, 5 minutes $0.145 and 1 hour $0.22. Haiku 5.5 prices depend on prompt length, so check which range your requests fall into first.

The 1.65 and 2.40 of a 0.1x model drop to 1.45 and 2.20. Fable 5.2 (0.025x) gave 1.35 and 2.10 at 4 minutes, and at 10 minutes 6.25 for 5 minutes and 2.10 for 1 hour. The read multiplier changes the values but not the order of 5 minutes and 1 hour in the three cases that were run.

[4] Do not design around the boundary. The docs call 5 minutes and 1 hour minimum lifetimes, say expired entries are deleted "promptly, though not immediately", and say an entry exists only after the response starts. So when a gap is exactly 300 or 3,600 seconds, the script gives no cost for that TTL and exits with code 3.

console
$ python3 ttl.py 0.1 0,300; echo "exit=$?"
output
none cost=2.00005m   undecided: a gap equals the TTL (300 s)1h   cost=2.1000 hits=1 misses=1exit=3

If that gap were a read, the 5-minute figure would be 1.35; as a write it would be 2.50. Do not schedule requests right at the limit. The gap runs from the start of one request to the start of the next, not from the end of the response, so it includes the time spent generating the response. For example, you could keep start-to-start gaps under 4 minutes for the 5-minute cache and under 50 minutes for the 1-hour cache. Those margins are examples, not limits from the docs.

If an expired entry lingers briefly, the expiry part of this calculation, which counts every gap beyond the TTL as a write, can overstate the cost. That does not make the total an upper bound: a miss from one of the causes in [5], such as a changed prefix, makes the real cost higher.

ttl.py was compared with a separate, longer calculator on 116 lists of request times (100 of them random) at all three read multipliers, and all 348 results matched. Twelve kinds of bad input, including empty values, times out of order, equal times, and negative, NaN and infinite values, ended in an error instead of a number. Three copies, with the boundary handling, the equal-time check and the read calculation broken one at a time, all failed this comparison.

[5] Look for what makes the cache miss. Only items from the docs are listed. The calculation above assumes hits; if one of these prevents reads, you keep paying for writes.

  • The prefix changes. The cache is built in the order tools, system, messages, and a change in an earlier part invalidates everything after it. Changing tool definitions invalidates all of it.
  • cache_control sits on a block that changes every request, such as a timestamp or the incoming user message. Put it on the last block that stays identical.
  • tool_choice, the presence of images, the thinking configuration or output_config.effort differ between requests.
  • The prompt is shorter than the model's minimum length.
  • In a growing conversation, the last write falls more than 20 blocks behind the breakpoint, outside the lookback window.
  • A language that randomizes JSON key order (the docs name Swift and Go) changes the key order of tool_use blocks.

[6] In real traffic, confirm with the response usage. cache_creation_input_tokens counts tokens written, and cache_creation.ephemeral_5m_input_tokens and ephemeral_1h_input_tokens split those writes by TTL. cache_read_input_tokens counts tokens read, and input_tokens counts tokens after the last breakpoint. Count over several days of logs how many requests fall into each row of the table, and whether 5-minute writes repeat without reads (ephemeral_5m_input_tokens piling up), then pick the TTL. With server tools such as web search, you may see 5-minute writes you did not request. The docs say server tool results are cached automatically, so count those requests separately. Neither "1 hour is always cheaper" nor "5 minutes is always cheaper" came out of the table above.

#claude-api#prompt-caching#cache-control#ttl#pricing