APIIntermediateClaude API
Put the fixed part first in the prompt or the cache never hits
Prompt caching works on a stable prefix: if variable content goes at the top, the prefix changes on every request and you save nothing.
Always order static before dynamic: first the big block of instructions, then what is specific to each request (e.g. the document to analyze). Mark the boundary of the cacheable prefix and match the TTL to how often it is used. Careful: writing to the cache has a cost; if the prompt is called rarely or its fixed part is small, it can end up more expensive. Check the current syntax in the official docs.
Example
Recommended order: [1] Instructions and guides (fixed, cacheable) [2] Fixed examples --- prefix boundary --- [3] This request's document/query (variable)