Prompt Caching with DeepSeek: Pay Less for Repeated Context

Cached input costs a fraction of normal input. How prompt caching works with DeepSeek V4.1 and how to order your prompt so it hits the cache.

2 min read

deepseekcachingcost

Glowing glass blocks stored in a cool cabinet, one sliding out again beside a small coin

Many applications send the same text again and again: a long system prompt, a product manual, a codebase summary, the earlier turns of a conversation. With prompt caching, the repeated part is read from cache and billed at a much lower price. There is nothing to switch on. You only have to arrange your prompt so the cache can do its job.

The price difference

For deepseek-v4-1-flash, per million input tokens:

StandardOff-peak
Input, not cached$0.21$0.105
Input, read from cache$0.0042$0.0021

Output tokens are not affected by caching. They cost the same either way.

How the cache matches

The cache works on prefixes. When a new request starts with exactly the same tokens as an earlier one, that shared beginning can be read from cache. As soon as one token differs, everything after it is new input.

So the rule is simple: put what stays the same first, and what changes last.

Ordering a prompt for the cache

A typical request has four parts. In the right order:

  1. System prompt: instructions, persona, output format. Identical every time.
  2. Reference material: the document, the manual, the schema, the code. Identical for every question about it.
  3. Conversation history: grows, but the earlier turns stay the same.
  4. The new question: always different. Last.
python
messages = [
    {"role": "system", "content": SYSTEM_PROMPT},             # same every time
    {"role": "user", "content": f"Manual:\n{MANUAL_TEXT}"},   # same for this manual
    *history,                                                 # earlier turns, unchanged
    {"role": "user", "content": question},                    # new
]

What breaks the cache

  • A timestamp or request id at the top of the system prompt. Move it to the end, or drop it.
  • Reordered documents. Sort them the same way every time.
  • Small edits to the system prompt. Fine when you mean them, but each version starts a new cache.
  • Rewriting history. Summarising or trimming earlier turns changes the prefix. Do it rarely and in larger steps, not on every turn.

Checking that it works

The Usage page splits your input tokens into cache hits and cache misses for each model and day, and shows your cache hit rate for the period. Run the same request twice, then look: the second request should have read most of the shared prefix from cache. If the hit rate stays low for a workload that repeats a lot of context, look for something near the top of the prompt that changes on every request.

Where it pays off most

  • Coding agents such as Cline and Claude Code, which resend a lot of context on every step.
  • Chat over a document: every question about the same manual reuses it.
  • Batch jobs with one long instruction block and a short item each time.
  • Multi-turn conversations, where earlier turns are resent with every message.

Caching and the off-peak window work together: a batch job with a long shared prefix, run off-peak, pays the least on both counts.

Also in Tiếng Việt, Español, Português, Bahasa Indonesia, Français, 简体中文