# Prompt Caching

> The Prompt Caching is a technique of reusing the processed beginning of a prompt to reduce latency and cost.

## What is prompt caching and how does it reduce LLM cost?

The technique where an LLM API stores the processed prefix of a request, such as system prompt, tools and documents, and reuses it in next requests. Cached tokens are much cheaper and faster, so stable content should go first.

- Topic: APIs & Integrations
- Type: technique

## Example

Wrong:

```text
Today is {current_datetime}. Request ID: {request_id}.
You are a support assistant for Acme.
{long_product_docs}
User: {question}
```

Right:

```text
You are a support assistant for Acme.
{long_product_docs}
Today is {current_date}.
User: {question}
```

Moving changing values after the stable instructions and documents keeps the prefix identical, so the cache can hit.

## Common mistakes

- Putting the current date at the top of the system prompt, so the cache never hits.
- Reordering tools or examples between requests, which breaks the shared prefix.

## Key points

- Stable content like the system prompt, tools and documents comes first, and changing content like the user message comes last.
- Nothing that changes per request, such as a timestamp or request ID, is placed inside the cached prefix.
- Cache hits are measured from the usage fields in the API response, not assumed.

## Interview questions

### Prompt caching vs response caching: what is the difference?

Prompt caching reuses processed input inside the model API, and the model still generates a fresh answer. Response caching returns a stored answer without calling the model.

### How long does a prompt cache last?

Usually only a few minutes since the last use, though some APIs offer longer options. Check the provider docs and measure hits in usage data.

### Is prompt caching automatic?

Some APIs cache matching prefixes automatically, others need explicit cache markers in the request. In both cases only an identical prefix can hit.

## Related cards

- [Token Cost](https://wonderium.dev/ai/token-cost.md)
- [Latency](https://wonderium.dev/ai/latency.md)
- [System Prompt](https://wonderium.dev/ai/system-prompt.md)
- [Context Window](https://wonderium.dev/ai/context-window.md)
- [CDN](https://wonderium.dev/web/cdn.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/prompt-caching
- Last updated: 2026-11-25
