Module 8 · Lesson 2 of 4

Reusing a shared prompt start

Read the shared start once

A prefix cache keeps the saved work for a prompt's fixed start, so prefill reads only the new part at the end.

Scene 1 of 4 · The same long start

Every request starts with the same 3,000 tokens of instructions, then a 50-token question.

Prompt tokens prefill reuses or reads fresh (3,000 fixed, then a 50-token question)
  • Reused0 tokens
  • Read fresh (highlighted)3,050 tokens
Prefill time
not shown yet
Input cost (example prices)
not shown yet
  1. The same long start. Every request starts with the same 3,000 tokens of instructions, then a 50-token question.
  2. No prefix cache. Without a prefix cache, prefill reads all 3,050 tokens every time, about 122 ms at the lab's rate.
  3. Reuse the start. A prefix cache keeps the saved work for the start, so prefill reads only 50 new tokens.
  4. Often cheaper too. If cached input costs 10% of the price, input drops from $0.00915 to $0.00105 a request.
  5. Now you try. Lay out the prompt, and see how much of it the cache can reuse. For example: 0 tokens reused, 3,060 read fresh: about 122 ms of prefill. Something that changes sits at the top, so nothing after it can be reused.

Scene 1 of 4: The same long start. Every request starts with the same 3,000 tokens of instructions, then a 50-token question.

Key points

  1. Most prompts start with the same long instructions.
  2. A prefix cache keeps the saved work for that shared start.
  3. Prefill then reads only the new tokens at the end.
  4. Anything that changes must come last, or nothing after it can be reused.

Many start with the same long instructions and differ only at the end, in the user's question.

A keeps the model's saved work for that shared start, its (see How a model writes). Then only has to read the new part.

This saves time, and often money, since many providers charge less for input read from such a . The start must match exactly, and the saved work expires, often after a few minutes.

Example. Illustrative: 3,000 tokens of fixed instructions plus a 50-token question. With a prefix cache, prefill reads about 50 new tokens instead of 3,050.

In system design: Put the fixed parts of a prompt first and the changing parts last, so the shared start stays identical and can be reused.

Check yourself

How should you order a prompt to get the most from a prefix cache?