ByteCosts
thinking-blocks-prompt-cache.mdx

AI Coding Agents

How thinking blocks interact with prompt caching

Thinking blocks affect prompt caching when a provider renders earlier reasoning into a later request. Anthropic documents retained thinking as input and cached thinking as cache reads during tool loops. OpenAI documents output billing and reasoning replay, while Gemini’s thinking guide requires exact thought block replay in stateless mode and documents generation charges without specifying how replayed blocks are cached.

Separate reasoning generation from history replay

A coding agent can generate reasoning before calling a tool, carry that reasoning into its next request, and use a cached prefix while processing the tool result. Those are distinct events for billing and context capacity. To estimate spend, first ask how many tokens the model generated. Then ask which of those tokens the provider rendered into later prompts and whether any of that input was read from cache. A short visible answer can sit on top of a larger generation bill, and a warm cache can coexist with a growing context window. Input tokens vs. output tokens

Anthropic bills newly generated thinking as output. Its usage reference gives usage.output_tokens_details.thinking_tokens as the reasoning portion of the inclusive output_tokens total. When Claude shows you a summary of its thinking, the billing count reflects the reasoning generated internally. Read the usage counters to price that portion of the request. If a model keeps that thinking on a later request, the retained block is input on the later request. A request can incur both charges because an earlier generation and a later replay are separate operations. Anthropic thinking cost

Provider and APIHow reasoning is carried forwardWhat the docs say about caching or billing
Anthropic MessagesModel-dependent preservation of returned thinking blocksNew thinking bills as output. Retained thinking counts as input, and cached thinking counts as input read from cache
OpenAI ResponsesReasoning items can be carried in managed state or replayed, including encrypted content in stateless modeNew reasoning tokens bill as output. Supported GPT-6 and later models in standard, single-agent mode can use configuration_update to preserve the cached prefix when changing effort
Gemini InteractionsResend all thought blocks exactly in stateless mode. Stateful mode manages them on the serverGenerated thought tokens contribute to response pricing. Gemini’s thinking guide gives no cache accounting rule for replayed signatures

Check what Claude preserves after each user message

As of November 30, 2026, Anthropic’s thinking docs put Claude Opus 4.5 and later Opus models, Claude Sonnet 4.6 and later Sonnet models, Claude Haiku 5.5, Claude Fable 5, 5.1, and 5.2, Claude Mythos 5, 5.1, and 5.2, and Claude Mythos Preview in the keep-all-prior-turns group. Earlier Opus and Sonnet models and Haiku models through Haiku 4.5 keep thinking for the turn in progress. On last-turn-only models, the API strips older thinking when the next user message contains something other than a tool result. A chain of tool results can still reuse earlier thinking within its active turn. Anthropic thinking

During a tool loop, the follow-up request with tool results can cache earlier conversation history, including thinking blocks. Anthropic says this handling of thinking works automatically in the loop, even without explicit cache_control markers for it. On keep-all models the blocks also stay in context across user turns. Budget context space for these blocks even when they are part of a cache hit. Last-turn-only models remove the blocks when a new user turn starts, which changes the prefix from the first removed block onward. Anthropic thinking, Anthropic cache breakpoints

When your client continues a tool loop, pass back the returned thinking blocks unchanged with the rest of the assistant turn. Anthropic checks the prefix for blocks on its preserved-thinking models. Changing system, tools, or an earlier message can cause a block after the change to fail that check and the request can return a 400 error. If you need to reclaim context space, Anthropic’s server-side clear_thinking_20251015 strategy controls how many earlier thinking turns to keep. Clearing invalidates the cached prefix from the clearing point. The two operations have different consequences for replay: server-side context editing keeps the client’s original conversation history intact, while a client rewrite changes what the service checks. Anthropic thinking, Context editing

Change effort without rewriting old history

Anthropic renders the thinking configuration and resolved effort into the model’s prompt. Switching thinking modes or changing a supported legacy budget_tokens setting invalidates message-level breakpoints and can invalidate tool and system breakpoints too. For changes to top-level effort, a message-level breakpoint can miss on any model. Tool and system breakpoints can also miss on Claude Opus 5, Claude Sonnet 5, Claude Fable 5, Claude Mythos 5, and earlier models that support effort. Anthropic recommends budgeting as if a thinking configuration or top-level effort change invalidates the whole cache. Anthropic thinking

Anthropic demonstrates this with a message-level breakpoint on Opus 5.5. In its documentation example, the second request reads 3,546 cached input tokens at medium effort. The third switches to low at the request level and reports cache_creation_input_tokens of 3,546 and cache_read_input_tokens of zero. That’s the observed example in the docs. The size of the rewrite in your application depends on where you set the breakpoint and how much of the prefix was warm. Anthropic thinking cost

On supported models and configurations, the Messages API offers a per-message effort beta. Keep the request’s top-level effort unchanged and append a role: "system" item inside messages, with empty content and the new output_config.effort value. For the first-party Claude API, the docs require the mid-conversation-output-config-2026-07-01 beta header. This leaves the cached prefix intact. The change takes effect on a user turn with new input. A message containing only tool results doesn’t qualify, so an effort update planned for the middle of a tool-only loop can wait until later. Check the availability table for your model and platform, and apply Claude Code’s separate client rules when using Claude Code. Per-message effort, Coding agent effort routing

Preserve OpenAI reasoning items and Gemini signatures

In OpenAI’s Responses API, generated reasoning tokens count as output and are reported in usage.output_tokens_details.reasoning_tokens. When continuing a function call, carry the reasoning items through with the tool results. With store: false, reasoning items in the response’s output array include encrypted_content by default. For stateless all_turns replay, keep every output item in order, append the next user message, and replay the complete history. OpenAI reasoning

GPT-5.6 models render available, compatible reasoning from earlier turns by default. OpenAI says earlier models default to current-turn reasoning. Which items the API can see, and which ones it renders, are separate questions. For an effort change on supported GPT-6 and later models in standard single-agent mode, append a configuration_update input item and keep request-level reasoning.effort unchanged. OpenAI documents prefix preservation for this update. The cited reasoning and caching guidance gives no separate cached-token accounting rule for the encrypted reasoning items. Use the returned usage totals when comparing requests. OpenAI reasoning, OpenAI prompt caching

In Gemini’s Interactions API, thought signatures represent internal reasoning and let the model continue across turns. In stateless mode, where the client passes the full history, resend all thought blocks exactly as received. When built-in tools such as Google Search return their own tool result signatures, resend those signatures in later stateless turns. In stateful mode the server handles signatures. Gemini’s thinking guide documents thought-token billing for generated reasoning and gives no cache accounting rule for replayed signatures. Build replay according to the API contract and keep any savings estimate tied to usage you can verify. Gemini thinking

Price a 30-turn Opus loop with one cache rewrite

Assume 30 requests in an Opus 5.5 tool loop, each producing 700 billed output tokens including 400 thinking tokens. Start with an 8,000-token cacheable prefix. On each later request, append 1,200 cacheable tokens, of which 400 are retained thinking from the preceding response and 800 are other history, such as the tool call and result. Every request has a 200-token uncached tail. The fixed increments are scenario inputs. In an actual loop, record generation and the size of preserved thinking separately.

Assume five-minute writes, timely requests, and a message-level breakpoint that lets each request read the previous prefix and write its new part. Use $4 per million uncached input tokens, $0.20 per million cache reads, $5 per million writes, and $20 per million output tokens. The formula is the sum of tokens in each bucket multiplied by that bucket’s rate, divided by one million. The initial write is 8,000 tokens. In the steady case, the subsequent 29 reads rise from 8,000 to 41,600 by increments of 1,200. Each of the 29 later requests writes its 1,200-token append, for a total of 42,800 written across the session. ByteCosts pricing index

For the second estimate, change top-level effort on request 16. Assume the message breakpoint misses, replacing a 24,800-token read with a write of the same 24,800 tokens. That request writes 26,000 tokens altogether, including the planned 1,200-token append. The estimate holds output and all later prefix sizes fixed to isolate the billing effect of replacing the read. A later resumption of the original effort or a different breakpoint layout would require its own cache accounting.

Estimated usage or costConstant effortOne top-level effort change
Uncached input tokens6,0006,000
Five-minute write tokens42,80067,600
Cache read tokens719,200694,400
Output tokens21,00021,000
Estimated total$0.80184$0.92088

The rewrite costs an estimated $0.11904. It’s the 24,800 tokens multiplied by the $4.80 per million gap between writes and reads. To break even through output reductions alone at the assumed output rate, the remaining requests would need to produce at least 5,952 fewer billed output tokens in total. If the shorter output also changes the size of later cached history, recalculate both reads and writes. At the next eligible user turn, a supported per-message effort update preserves the existing prefix.

Decide what to measure before changing retention

Start with a trace where the model, tool results, and effort stay fixed. Collect Claude’s input_tokens, cache_creation_input_tokens, cache_read_input_tokens, and output_tokens for every request. Record where a user message starts a new turn and where a setting changes. Follow a rewrite through the next stable request to see whether cache reads resume. If you’re close to the context limit, try server-side thinking clearing at a known point and check whether shorter history improves the subsequent requests enough to justify the rewrite. Anthropic prompt caching

Compare task outcomes along with the bill. A shorter thought history is useful only if the loop still completes with the evidence needed to validate the patch. For the output half of the bill, continue with reasoning effort and token cost. For a policy that escalates selected turns, use the effort router and set the cache capability for the connection you tested.

Sources

Interactive report

  • The Hidden Thinking Bill: Two agents can return the same brief answer and leave very different bills. Follow the tokens they generate, the history they carry forward, and what happens when you change effort mid-task.

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.

How thinking blocks interact with prompt caching. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/thinking-blocks-prompt-cache/

Sources