Prompt caching
Definition
Reusing the processed form of a repeated prompt prefix, such as a long system prompt, across requests to reduce latency and cost.
In more detail
Long system prompts, tool definitions and documents that stay the same between calls can be cached by the provider. Some APIs cache automatically; others, such as Anthropic's, let you mark where the cached prefix ends. Put stable content first and variable content last to benefit.
Related terms
Latency
The time from sending a request to a model to getting the response, often split into time to first token and total generation time.
Token
The unit of text a model reads and writes, often a word or part of a word; in English a token averages about four characters of text.
Contextual retrieval
Adding a short, model-written note on where each chunk sits in its source document before embedding and indexing the chunk.
KV cache
Memory where a transformer stores attention keys and values for tokens it has already processed, so it does not recompute them each step.
Semantic caching
Reusing a stored model response when a new request means the same as an earlier one, judged by embedding similarity rather than exact text.
Time to first token
How long a model takes to return the first token of a response after a request, the main driver of how fast a streamed reply feels.
Read more about Prompt caching
- Cut LLM costs with prompt caching and token budgets
Lay out prompts so the provider can cache them, measure tokens before you send, and use batch processing and model routing to cut what each request costs.
- LLM cost levers cheat sheet
The main ways to cut model spend, ordered by effort, with what each saves, what it risks and how to check quality held. Checked against provider docs.
- LLM cost optimisation
Cutting LLM costs with caching, model routing, batching and budgets.