Knaph

Prompt caching

The provider keeps the work done on the start of a request (the prefix) for a few minutes, so a later request that begins with exactly the same tokens reads that part at about a tenth of the price, and faster. Any change near the start means everything after it is processed again.

Depth 1 · Foundation

You can explain why long agent sessions cost far less than resending everything would, what breaks the cache, and how to keep it working.

Sign in to prove what you know with a short quiz, see how deep you've gone, and earn XP for it.

Sign in with Google

Depths of understanding

  1. 1
  2. 2

    Deeper

    You can build it: put a cache_control marker at the end of the system prompt, which covers the tools and the system prompt, and send cache_control on the request so the newest message is cached too; then read cache_read_input_tokens and cache_creation_input_tokens to see it working, and keep anything that changes out of the start of the request.

    Master depth 1 first

Your path here

What's still between you and Prompt caching, depth 1, in the order you can learn it.

  1. 1Language modelDepth 1 · Foundation · Language Models
  2. 2TokenDepth 1 · Foundation · Language Models
  3. 3CountingDepth 1 · Foundation · Number Systems
  4. 4Comparing numbersDepth 1 · Foundation · Number Systems
  5. 5ProbabilityDepth 1 · Foundation · Probability
  6. 6Flat shapesDepth 1 · Foundation · Geometry
  7. 7Equal partsDepth 1 · Foundation · Fractions
  8. 8LengthDepth 1 · Foundation · Measurement
  9. 9LengthDepth 2 · Deeper · Measurement
  10. 10Equal partsDepth 2 · Deeper · Fractions
  11. 11FractionsDepth 1 · Foundation · Fractions
  12. 12ProbabilityDepth 2 · Deeper · Probability
  13. 13ProbabilityDepth 3 · Connected · Probability
  14. 14ProbabilityDepth 4 · Deeper still · Probability
  15. 15ProbabilityDepth 5 · Deeper still · Probability
  16. 16Next-token predictionDepth 1 · Foundation · Language Models
  17. 17Thinking tokensDepth 1 · Foundation · Language Models
  18. 18Token costDepth 1 · Foundation · Language Models
  19. 19Stateless modelDepth 1 · Foundation · Language Models
  20. 20Prompt cachingDepth 1 · Foundation · Language Models

Where it fits