AI Coding Agents
Anthropic vs OpenAI prompt caching for coding agents
Claude’s Messages API opts into prompt caching with explicit block markers or an automatic marker. OpenAI’s Responses API uses implicit boundaries by default and adds explicit control on GPT-5.6 and later. Cache boundaries, lifetime, and isolation determine whether an agent can reuse its prefix and how much it pays to rebuild it.
The mechanics at a glance
The comparison uses the first-party API guides as of November 30, 2026. OpenAI has distinct rules for earlier models and GPT-5.6 and later. Anthropic’s minimum length and read discounts depend on the model. For the broader provider pricing overview, start with the separately maintained rate comparison.
| Decision | Anthropic Messages API | OpenAI Responses API, GPT-5.6 and later | OpenAI Responses API, earlier models |
|---|---|---|---|
| Where to cache | Block-level cache_control for explicit boundaries or a top-level marker that advances automatically | Implicit eligible message endings by default, optional prompt_cache_breakpoint markers, or explicit-only mode | Implicit breakpoints at model-dependent intervals |
| Lookup candidates and write slots | Up to four breakpoints, including the automatic one when enabled. Each checks up to 20 block positions, counting itself. | Up to four writes per request, including the implicit write slot when enabled. Both modes check the first two and latest 50 explicit breakpoints. Implicit mode also checks its own breakpoint, up to 20 earlier eligible message endings, and the end of the initial developer-message group. | Implicit breakpoints only |
| Minimum prefix | 512 tokens on Sonnet 5.5, Opus 5.5, and Haiku 5.5. Check other models separately. | 1,024 visible input tokens | Varies with model and request settings |
| Write rate relative to ordinary input | 1.25× for five minutes, 2× for one hour | 1.25× for 30 minutes, 2.5× for 12 hours | Ordinary input pricing, with no extra cache-write charge |
| Read rate relative to ordinary input | Usually 0.1×. Sonnet 5.5 and Opus 5.5 are 0.05×. The guide also lists 0.025× exceptions. | Usually 0.1×. GPT-6.2 Sol, GPT-6.1 Sol, GPT-6.2 Astra, and GPT-6.1 Terra are 0.05×. | Model-dependent |
| Lifetime control | cache_control.ttl selects the lifetime, with five minutes by default | prompt_cache_options.ttl sets the minimum, with "30m" by default and "12h" available | Model-dependent support for prompt_cache_retention values "in_memory" and "24h" |
| Scope of reuse | Isolated by organization and, on the Claude API, by workspace | Isolated by organization and processing region. Optional prompt_cache_key for separate accounting. | Same organization and region boundaries. A stable prompt_cache_key can help routing. |
The write multipliers are total rates for those tokens. Calculate each group of billed tokens once. In both APIs the chosen boundary can affect which tokens are ordinary input, which are written at a premium, and which are read at a discount.
Put a breakpoint where the next request can find it
Anthropic renders the cache hierarchy in the order tools, system, then messages. An explicit marker writes an entry through the marked block, including that block. A top-level marker moves the breakpoint to the last eligible block as the conversation grows. The API can look back up to 20 positions per breakpoint, counting the breakpoint itself. It can find only an entry that some earlier request actually wrote. On the Claude API, consecutive runs of tool_use or tool_result blocks count as one position per run.
Consider an agent that appends a fresh issue description to the same repository instructions on every request. A marker after the issue description can produce a new write for each distinct issue. The lookback can find the shared instructions only if an earlier request wrote an entry at their boundary. Put a marker at the end of those instructions to make them independently reusable. The Anthropic breakpoint guide explains how to manage a growing history alongside that stable entry.
On GPT-5.6 and later, OpenAI implicit mode chooses the end of the latest eligible message. Eligible endings include a user message, the last response in a consecutive tool-response group, and the last developer message in the initial consecutive developer-message group. Explicit markers can coexist with that implicit breakpoint. For a stable repository prefix followed by a changing issue description, use prompt_cache_options.mode set to "explicit" and mark the stable boundary. The changing suffix after the last selected breakpoint is billed as ordinary input. Preserve the marked endpoint in subsequent requests.
There is a separate placement rule for GPT-6.2 and later. These Responses API models append top-level instructions after input and bill them as uncached input. Put reusable instructions in the first developer message within input. If you use explicit-only mode, mark the supported content block where that stable portion ends. For the effects of migrating an older integration, see the GPT-5.6 cache changes guide.
OpenAI’s guide points to a Prompt Caching Dashboard for hit rates and a Prompt Cache Diagnostics tool for misses. An open Codex issue (#62312, opened November 18, 2026, and still open as of November 30, 2026) reports that top-level instructions on gpt-6.2-sol showed zero cached tokens for that content, while the same text in a leading developer message began caching on the second step. That matches the documented placement rule. The reporter also saw diagnostics report a hit while response usage showed zero cached and written tokens. Use the response’s usage counts for cost estimates.
Diagnose prefix changes, expiry, and routing separately
On Anthropic, changes to tool definitions can invalidate the tools, system, and message caches. A tool_choice change affects message blocks. The effect of thinking and effort changes depends on the model and which parts of the prompt they alter. OpenAI lists model, tools, parallel_tool_calls, text.format, reasoning.effort, text.verbosity, and context_management for compaction as settings that can change the rendered prefix. On supported GPT-6 and later models, append a configuration_update input item to change effort while keeping top-level reasoning.effort at its original value and preserving the earlier prefix. Both APIs can lose reuse after an edit before the selected boundary, so preserve shared context and test request-setting changes individually.
A compatible prefix can still miss after a gap. Anthropic refreshes the lifetime when the entry is used. If you mix one-hour and five-minute markers in a request, put longer-lived entries first. For OpenAI’s newer models, a 30-minute read refreshes coverage to at least 30 minutes after the read, preserving any existing 12-hour expiry if that is later. An upgrade from 30-minute to 12-hour coverage incurs a new write for the upgraded tokens. For earlier OpenAI models, in-memory entries typically last about five to ten idle minutes, up to an hour, and models supporting extended retention can keep entries for up to 24 hours.
When comparing different lifetimes, start each run with a fresh prefix. Anthropic documents that a read of an existing five-minute entry restarts its five-minute lifetime even if the reading request asks for one hour. OpenAI bills a qualifying upgrade as a new write, so changing the option partway through a run can also change the billing mix. Capture the lifetime of the original write and the usage on the first read before interpreting a gap test. OpenAI’s minimum lifetime governs eligibility for cache-read pricing, and its guide treats actual tensor reuse and latency separately.
OpenAI documents machine-local cache state and routing that considers load, capacity, and a hash of initial tokens after its hidden content. On earlier models, a stable prompt_cache_key helps related requests reach a cache holding their prefixes. OpenAI advises roughly 15 requests per minute across prefixes using each key on those models. Higher traffic can overflow to another machine. On GPT-5.6 and later, OpenAI routes automatically and documents the optional key for separate cache accounting. Requests across organizations or processing regions cannot share the cache. On the Claude API, a second workspace in the same organization builds its own cache too. Keep the isolation scope consistent when comparing otherwise identical requests.
Read the provider’s usage before diagnosing a miss
In the Claude API response, usage.cache_read_input_tokens counts reads and usage.cache_creation_input_tokens counts writes. Add both to usage.input_tokens to get total input. On the first request using cache diagnostics, a beta Messages feature, pass diagnostics.previous_message_id as null. On the next request, pass the previous response ID. The API reports where the request structure diverged, independently of whether you got a cache hit. Read diagnostics alongside the token counts to distinguish an input change from a matching request with no available entry. The Claude cache diagnostics guide walks through that comparison.
In Responses API usage, read usage.input_tokens_details.cached_tokens and, on supported models, usage.input_tokens_details.cache_write_tokens. Subtract both from total input to get ordinary input. When both lifetimes are used, cache_write_tokens_details splits the writes into ttl_30m_tokens and ttl_12h_tokens. Price the two groups separately.
Estimate the same 50-turn session on both models
Assume a coding agent issues 50 requests, each with a stable 8,192-token prefix, 1,024 ordinary input tokens after the breakpoint, and 512 billed output tokens. Treat those counts as equal across the models for comparison. In a real replay, use each model’s reported counts. Assume one initial write and 49 full reads of the shared prefix. Use Sonnet 5.5’s five-minute TTL and GPT-6.2 Sol’s 30-minute TTL. Set explicit boundaries so the changing suffix remains ordinary input, and assume the requests are close enough for both to stay warm.
Estimate cost by multiplying the tokens in each row by that row’s rate and dividing by 1,000,000. The two models have identical ByteCosts rates for ordinary input, output, reads, and the default writes, so this warm-session estimate is the same for both. The estimates diverge when the gap changes the mix of writes and reads.
| Billed portion | Session token count | Sonnet 5.5 rate | GPT-6.2 Sol rate | Estimated cost on each |
|---|---|---|---|---|
| Initial write | 8,192 | $2.50 | $2.50 | $0.02048 |
| Later reads | 401,408 | $0.10 | $0.10 | $0.04014 |
| Ordinary input | 51,200 | $2.00 | $2.00 | $0.10240 |
| Output | 25,600 | $10.00 | $10.00 | $0.25600 |
| Total | $0.41902 |
Now group the same requests into ten bursts of five with eight minutes between bursts. Assume each burst’s first turn needs a new Sonnet five-minute write and the OpenAI prefix stays eligible for reads. The Sonnet estimate rises to $0.59597, from 81,920 written tokens, 327,680 read tokens, and the same ordinary input and output charges. With a single Sonnet one-hour write at $4 per million, derived from twice the $2 input rate, and 49 successful reads, Sonnet instead comes to $0.43131. Under the stated hit assumptions, the GPT-6.2 Sol estimate remains $0.41902. Use the pricing index for current rates.
These estimates isolate the effect of the lifetime and reuse pattern. A growing history, a change in tool schemas, or unneeded writes of the suffix will produce different token groups. For actual costs, price the usage from each request and sum the resulting charges across the session.
Test your request shape before choosing a lifetime
- Choose a stable boundary. On Anthropic, mark the last unchanged block. On GPT-6.2 Sol, put durable guidance in the first developer message and keep the changing suffix after the chosen boundary.
- Replay a short sequence and then a typical idle gap. Keep the workspace, organization, region, and any applicable key consistent. Check whether the expected read disappears at the gap or at a specific prompt edit.
- Record writes as well as hits. Extract counts by lifetime when available, and price the entire session. Test the longer lifetime using the gaps your workload actually has. Keep the shorter lifetime when extra coverage does not save enough rewrites to cover the higher write rate.
Sources
- Prompt caching (Anthropic, accessed 2026-11-30)
- Cache diagnostics (Anthropic, accessed 2026-11-30)
- Prompt caching guide (OpenAI, accessed 2026-11-30)
- Codex issue #62312 (OpenAI Codex, accessed 2026-11-30)
Interactive report
- Who Pays to Remember: Give four APIs the same repeated prompt and open the bill one line at a time. The read discount is only the first entry.
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Anthropic vs OpenAI prompt caching for coding agents. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/anthropic-vs-openai-prompt-caching/