Question presented to candidate: "Our assistant sends the same 8,000-token system prompt and tool list on every request, and the provider dashboard shows something called cached input tokens. Explain what prompt caching actually is, why it makes requests cheaper and faster, and what we would have to change to benefit from it."
What a strong answer should cover:
- The mechanism: before generating, the model runs a prefill pass that computes attention keys and values (the KV cache) for every input token; prompt caching keeps those keys and values for a prompt prefix so a later request that starts with the same tokens skips that work
- Why it is a prefix and must be exact: each token's keys and values depend on every token before it, so one changed token invalidates everything after it, and the same text at a different position is a different cache entry
- Cost: cached input tokens are billed at a fraction of the normal input price (Anthropic documents reads at 0.1x and writes at 1.25x or 2x; OpenAI caches automatically and has historically charged no write fee), so the saving depends on the hit rate and the write surcharge
- Latency: skipping prefill cuts time to first token for long prompts, but output generation (decode) is not faster, so short-prompt or long-answer requests gain little
- Prompt design: stable content first (tools, system prompt, examples, documents), per-request data last; no timestamps or IDs at the front; and it is not the same thing as semantic caching of answers
Code / implementation expected: Optional โ a prompt layout with the stable prefix first, or a sketch of how a prefix match is computed and billed.