Measuring prompt cache hits on DeepSeek V4.1 Flash

DeepSeek

Calculate a token-weighted cache hit rate, handle missing usage counters and test how a shared prompt prefix changes the cost of a correctly handled ticket.

Published
On this page

Read the counters once per request

Two support tickets use the same returns handbook. The short request reports 900 cached tokens out of 1,000 input tokens. The long one reports 1,800 out of 9,000. Averaging their individual hit rates gives 55%. Yet only 27% of the input tokens in this batch hit the cache. If you are estimating the cost of processing a queue, use the second figure.

Keep the model ID, total input tokens, cached input tokens and ticket outcome together. Where the response includes cache details, look in usage for prompt_cache_hit_tokens or prompt_tokens_details.cached_tokens. These can describe the same tokens. If both are present, count them once and investigate any disagreement. When the response omits the cache counter, record it as missing. A reported zero is a usable observation.

Here is the calculation with the two fictional tickets. Output tokens are recorded separately and do not enter the denominator.

pythoncode
rows = [(1000, 900), (9000, 1800)]  # (input_tokens, cached_input_tokens)
total_input = sum(total for total, cached in rows)
total_cached = sum(cached for total, cached in rows)
print(f"{total_cached}/{total_input} = {total_cached / total_input:.0%}")

The result is 2700/10000 = 27%. If a third request has no cache counter, label the figure “27% across the two requests with cache data.” Keep the third request in your billing reconciliation.

Move a ticket number and test what changes

Prefix caching can reuse work already done on the beginning of an input. Consider a template that starts with a different ticket number on each request, followed by several thousand words of shared handbook text. The first difference appears before the handbook. Put the shared material first and append the ticket number and question. Preserve the roles and authority of the messages, especially when inserting customer text.

To test the change, choose a handbook you can use for testing and several distinct tickets with known answers. Prepare both layouts for each ticket. Change the order of material within the same message role and hold the model, output limit and questions fixed. Record the first pass separately, then compare repeated passes for the two layouts. A shared prefix is a chance for reuse; individual requests can still record zero hits. DeepSeek’s direct API documents a warm-up case: after A+B and A+C reveal a shared prefix A, a later A+D can reuse A once that prefix has been persisted. Measure the returned counters rather than assuming an immediate hit.[2]

Decide using the cost of a correctly handled ticket

For each layout, total the input and cache counters, then compare the actual charges and the number of tickets handled correctly. A cheaper answer that gives a customer the wrong return deadline creates another round of work. Charge any retries back to the original ticket before dividing batch cost by the number of accepted tickets.

A 27% input hit rate alone cannot tell you the discount on the bill. Price the cached input, the remaining input and the output at their applicable rates, allowing for any separately billed cache writes. The SmarToken DeepSeek V4.1 Flash model page explains the current pricing categories. For a completed batch, reconcile your estimate with the recorded charges. If latency is the only observation available, report the measured speed difference and leave the savings figure open.

Diagnose misses with three request patterns

The table below outlines a test plan; a live observation follows. Hold provider, model, message roles and output limits fixed, and record warm-up and repeat requests separately. Save sanitized cache-hit and cache-miss counters from usage, marking absent fields as unknown.

Request patternWhat to inspect
Identical prefixCheck reuse after warm-up; use the returned counters
Prefix changed midwayCompare what remains reusable before the change
Different beginningCheck whether an early change reduces the reusable prefix

Record request count, input tokens, hits, misses and test time for each group. Persistence timing, shared-prefix length and gateway field mapping can affect results; do not combine receipts from different providers.

On December 1, 2026, we ran a small test through SmarToken using deepseek-v4.1-flash. The synthetic handbook prefix was 12,040 characters; after two warm-ups with the same prefix, we sent one request each with the same prefix, a change in the middle and a change at the beginning. All five returned HTTP 200. Input and output token counts are shown below. Compared with the warmed handbook prefix, the three test inputs shared its first 12,040, 6,083 and 0 characters respectively. These are character counts, not billable token counts or proof that any prefix was cached.

RequestInput tokensOutput tokensCache hit / miss
Warm-up 1234824Not returned / not returned
Warm-up 2234824Not returned / not returned
Same prefix234824Not returned / not returned
Changed middle234024Not returned / not returned
Changed beginning236424Not returned / not returned

Below are the five original usage objects; case is our request label, not a field returned by the API. All five omitted cache-hit and cache-miss counters and prompt_tokens_details. These receipts cannot establish the hit rate or cache cost: missing is not zero, and it does not prove that caching failed. All five reached the 24-token output cap with finish_reason length; answer quality was not evaluated. This is one SmarToken route, not a result from DeepSeek’s direct API.

jsoncode
[
  {
    "case": "warm_1",
    "usage": {
      "prompt_tokens": 2348,
      "completion_tokens": 24,
      "total_tokens": 2372
    }
  },
  {
    "case": "warm_2",
    "usage": {
      "prompt_tokens": 2348,
      "completion_tokens": 24,
      "total_tokens": 2372
    }
  },
  {
    "case": "same_prefix",
    "usage": {
      "prompt_tokens": 2348,
      "completion_tokens": 24,
      "total_tokens": 2372
    }
  },
  {
    "case": "changed_middle",
    "usage": {
      "prompt_tokens": 2340,
      "completion_tokens": 24,
      "total_tokens": 2364
    }
  },
  {
    "case": "changed_start",
    "usage": {
      "prompt_tokens": 2364,
      "completion_tokens": 24,
      "total_tokens": 2388
    }
  }
]

A worked cache cost example

For a hypothetical 1 million input tokens on the direct DeepSeek API, suppose 98% are cached. At the off-peak deepseek-flash rates checked December 1, 2026—$0.003 per million cached input tokens and $0.15 per million uncached—the input cost is 0.98 × $0.003 + 0.02 × $0.15 = $0.00594. With no cached input, the same million tokens cost $0.15. Output is billed separately.[3]

This is an illustration, not a measured hit rate or invoice. Peak prices are different; calculate usage in each period separately, and use your own provider’s rates and billing records.

Sources

  1. DeepSeek V4.1 Flash model and pricing on SmarToken
  2. DeepSeek documentation on context caching
  3. DeepSeek direct API pricing