AI engineering · 27 of 42
Put the unchanging part first
Scroll
Put the unchanging part first
Providers can cache the processed form of a prompt prefix. Send the same opening bytes again and that portion is served from cache, at a fraction of the price and latency.
The match is on an exact prefix. Everything up to the first difference is reusable; everything after it is not.
Which makes ordering a design decision. Put the system prompt, tool schemas and stable documents first, and the volatile parts last. The classic own-goal is a timestamp or a session id near the top of the system prompt — it changes every call, so nothing is ever cached and you pay full price forever without any error to tell you.
Cost