OpenProgram Docs

Cache-control passthrough

A caller with a long fixed rule block followed by a dynamic tail wants the breakpoint after the rules. A caller's cache_control is an opaque dict, such as {"type": "ephemeral"} with an optional ttl, carried unparsed to Anthropic. The anthropic class only: native API and any anthropic-messages interface. OpenAI and codex classes use automatic prefix caching.

LayerWhereWhat happens
Content typesmodels/providers/types.pyTextContent and ImageContent carry cache_control: dict | None. Video and audio do not.
Context_build_pi_context in runtime/agent/runtime/Each content block's mark is copied onto its object. A role == "system" block becomes system_text, with no per-block breakpoint.
Cache policymodels/providers/settings/cache_policy.pyapply_cache_policy adds one mark to the last tool and one to the latest user message's last text block. It leaves caller marks alone and skips a message that already has one.
Wire_build_messages in adapters/anthropic/anthropic.pyThe mark is written into the block dict, for list-content UserMessage only. The automatic last-block breakpoint also lands on a final tool-result batch.

With no mark, the request body is byte-identical to one built without the field.

Automatic and caller breakpoints

_mark_final_message puts the automatic breakpoint on the last block of the request: the person's message on a turn's first round, the batch of tool results on every later round, so each round reads the whole history from the cache.

If any block in that message is marked, it gets no automatic breakpoint. An automatic one would spend a slot and pin the boundary past the content that changes.

A 1h breakpoint never follows a 5m one, which Anthropic rejects: the policy pass takes 1h only when the system breakpoint has it, and once a 5m breakpoint appears, a caller's included, every later breakpoint takes 5m.

What the caller must respect

BoundaryEffect
Minimum prefixBelow 1024 tokens (2048 for Haiku) before the mark, Anthropic ignores it silently: cache_read stays 0, and the passthrough is not at fault
Four breakpoints per requestA fifth returns 400. The system block, last tool, latest user message and last block can already use them. When caller marks push the count past four, the earliest message breakpoints are dropped and the last block keeps its own
ProxiesA proxy that strips cache_control keeps cache_read at 0. Test by sending one fixed prefix twice and checking the second response has cache_read > 0
Other providersTheir block construction reads .text and .data; the two model_dump() calls dump options, not content, so the field never leaks. TextContent.model_dump() round-trips, so persistence is unaffected

Caller's work

Put the fixed rules in the first text block and mark it. For OpenAI and codex, putting the stable prefix first is enough.

Implementation status

Implemented. tests/unit/programs/tools/test_cache_control_passthrough.py covers runtime-to-body passthrough, images, an unmarked identical body, the automatic breakpoint with no mark, no overwrite of a marked last block, and suppression for an earlier mark. tests/unit/providers/adapters/anthropic/test_anthropic_cache_breakpoints.py covers the tool-result breakpoint on later rounds, the four-breakpoint cap, one lifetime off api.anthropic.com, and a caller's 5m mark shortening the later breakpoints.

The non-Anthropic no-leak property was verified by reading the code. Passthrough through a real proxy is unverified.

Last updated · 2026-11-25