Chapter C · 3 of 4~8 min

Prompt caching

Reuse **identical prefix tokens** — same system prompt or RAG block every request? Cache it.

Paths & resources for this lesson

1Try it yourself

Playground

Prompt cache lab

Reuse identical prefix tokens — cut cost and latency when system prompt or RAG block repeats.

Same system prompt every request

2Read & reflect

Recap

#What you just did

You picked cache vs skip for repeated vs one-off prompts.

Teach

#How it works

Cache-friendly patterns:

  • Stable [system prompt](/reference/system-prompt) at the start
  • Fixed RAG context block before user message
  • Same tool schemas every call

Changing the prefix busts the cache. Put volatile user text after the static block.

Use it

#When you'd use this

  • High-volume APIs with identical instructions
  • RAG apps with shared doc bundles per tenant

Watch out

#Watch out

Cache discounts vary by provider. Measure — don't assume every prefix qualifies.

Try next

#Try this next

Reorder one prompt: static system + docs first, user question last.

3Spark check

Continue learning · glossary & guides