Question presented to candidate: "We run the same agent on Claude and on an OpenAI model. Each request carries about 10,000 tokens of tools, instructions and reference docs, and caching is barely showing up on either bill. How do the two providers' prompt caches actually work, and what would you change to cut the cost?"
What a strong answer should cover:
- The shared mechanism and the shared rule: both reuse an exact prompt prefix, so the prompt must be laid out stable-first (tools, system, documents, history) with per-request data last
- Anthropic specifics: explicit
cache_controlbreakpoints (up to 4) or one automatic top-levelcache_control, the tools-system-messages order, a 5-minute lifetime refreshed on each hit or a 1-hour option, writes billed at 1.25x or 2x and reads at a fraction of the input price, model-specific minimum lengths - OpenAI specifics: automatic caching from 1,024 tokens in 128-token steps with no code change, routing by a hash of the prompt start plus an optional
prompt_cache_key, in-memory versus extended (24-hour) retention, and the newer explicit-breakpoint mode on recent models - Economics: a write surcharge means caching is a bet on reuse inside the lifetime; picking the lifetime from the traffic pattern (busy, sparse, bursty) and computing the break-even
- Measurement: reading
cache_read_input_tokens/cache_creation_input_tokensorcached_tokensper request, tracking hit rate per prompt version, and catching the deploy that silently breaks the prefix
Clarifying questions expected:
- What does the traffic look like per prompt prefix: steady, bursty, or a few requests an hour?
- Which parts of the prompt change per tenant, per user and per request?
- Which exact models are in use (minimum cacheable length, discount and retention options are per model)?
Code / implementation expected: Optional โ request shapes for both providers with the cache controls, plus the cost arithmetic for the chosen lifetime.