DeepSeek context caching automatically discounts qualifying repeated input prefixes. Your application does not need a separate cache-write request. A later prompt can receive a cache hit when it fully matches a persisted prefix unit; the API reports hit and miss token counts so actual savings can be measured.

What is cached

Large language model requests often resend the same system prompt, examples, documents or prior conversation. DeepSeek’s disk cache stores reusable prefix work. When a later request begins with matching cached content, those tokens can be fetched at the cache-hit rate.

This is prefix caching. Matching text in the middle of a prompt is not enough if earlier tokens differ. Token-level identity matters, so small changes near the beginning can reduce reuse.

Current persistence rules

DeepSeek’s updated guide describes three ways prefix units are persisted: at request boundaries, when common prefixes are detected across requests, and at fixed token intervals for long inputs or outputs. Each prefix unit is standalone and must be fully matched by a subsequent request.

The implementation can evolve. Treat these rules as current only on the verification date and link to the official guide in engineering documentation.

Price effect

On 2026-07-30, V4 Flash cached input cost $0.0028 per million tokens versus $0.14 for uncached input. V4 Pro cost $0.003625 versus $0.435. Output pricing was unchanged by input cache status.

Use the response fields prompt_cache_hit_tokens and prompt_cache_miss_tokens to calculate actual cost. The pricing guide stores the central rates and the calculator guide provides formulas.

Design prompts for reuse

Put stable instructions and shared reference material first. Place user-specific questions and volatile metadata later. Keep formatting, whitespace and message order stable where they do not need to change.

Avoid leading timestamps, random IDs or per-request greetings. If audit IDs are required, send them in a provider-supported metadata field or later content rather than before the shared prefix, subject to the API specification.

Good workloads

Caching is useful for multi-turn conversations that resend history, analysis over the same long document, coding assistants that repeatedly include repository guidance, and classification systems with a long fixed policy. Few-shot examples can also form a stable prefix.

It is less helpful when every request has different content from the first token, prompts are short, or the application frequently reorders instructions. Measure rather than assuming.

Conversation design

Each chat-completions request normally includes relevant history. DeepSeek can cache matching earlier turns. As history grows, summarise or remove turns no longer needed; a discounted token still consumes context and adds data exposure.

Do not insert changing tool results ahead of stable system instructions. Maintain a consistent message template. For multi-user applications, use the documented isolation controls and never allow one user’s cached context to leak into another workflow.

Privacy and isolation

Caching is a provider-side optimisation, not your application’s private memory. DeepSeek documents user_id for KV-cache isolation, scheduling and safety distinctions. It must be a constrained opaque string and should not contain personal information.

Your own logs and prompt store still need retention controls. Do not cache secrets merely to save money. Remove content when the task no longer needs it.

Common mistakes

The largest mistake is pricing all input as a hit before observing usage. Another is changing a shared prompt on every request. Developers may also mistake semantic similarity for exact prefix reuse or assume that local client caching changes the provider’s token bill.

Do not use cache savings to justify a one-million-token prompt. Long context can still degrade retrieval and increase total cost.

Testing cache behaviour

Send a controlled sequence with a long stable prefix and a changing final question. Record hit/miss counts, model ID, request order and time. Then change one early token and compare. Use non-sensitive synthetic data.

Repeat after model or prompt migrations. Do not publish a measured hit rate as universal; it belongs to that workload and period.

Failure and freshness

The cache should not be the source of truth for changing reference data. If a policy or price changes, update the stable prefix and accept the temporary cache miss. Stale cheap context is more costly than a correct uncached request.

Version long reference blocks and include an effective date. Confirm that all users move to the new version rather than mixing cached and updated business rules.

Caching with tool loops

Agent workflows can reuse long instructions and prior messages, but tool outputs introduce changing content. Keep the fixed tool policy and schemas stable. Size-limit results so they do not dominate later requests.

Track cost across the full agent task. Cache hits can reduce input price while additional turns and reasoning increase output.

Caching is only one part of application design. The DeepSeek API guide covers key handling and request setup, while this page focuses on prefix reuse and measurement.

Conclusion

DeepSeek context caching can make repeated-prefix workloads much cheaper without a special API. Design stable prefixes, inspect actual usage fields and keep freshness, privacy and context quality ahead of savings. Reverify rates and rules when the API changes.

Useful next steps

Continue with related guidance

Put this page in context with DeepSeek API Guide: Setup, Keys and First Request, DeepSeek Pricing Guide: Chat, API and Model Costs, DeepSeek API Pricing Explained Per Million Tokens, and How to Estimate Your DeepSeek API Cost. These links cover the broader decision and the closest follow-up topics without repeating this article.

Common questions

Frequently asked questions

Do I need to enable caching?

DeepSeek says context caching is enabled automatically.

Does similar text count as a hit?

The documented mechanism requires matching persisted prefixes, not merely similar meaning.

Does a cache hit reduce output cost?

No. It changes the rate for qualifying input tokens; output uses its normal rate.

How can I see hits?

Inspect the response usage fields for prompt cache hit and miss tokens.

Evidence

Sources

3 primary references
  1. Context Caching — official external destination

    DeepSeek · official API documentation · verified July 30, 2026

  2. Models & Pricing — official external destination

    DeepSeek · official API pricing documentation · verified July 30, 2026

  3. Your First API Call — official external destination

    DeepSeek · official API documentation · verified July 30, 2026

Continue reading