GUIDES · CACHING

Cutting long-context cost with prompt caching

Long prompts look expensive per token and often are not. Cached input is billed at a small fraction of the normal input rate, so the same 200K-token context can cost twenty times less on the second call than on the first.

BASE URL https://apikey.help/v1 MODEL deepseek-v4.1-flash-1017

01How the caching works

The provider keeps a prefix of your prompt in memory. On the next request, if the beginning of your prompt is byte-identical to a cached prefix, those tokens are billed as cache hits instead of normal input. The saving is large: cache-hit input is roughly 2% of the cache-miss rate.

Two properties follow, and both matter more than any tuning parameter:

02Measured hit rates

Numbers from real traffic through this endpoint, not from a synthetic benchmark:

ScenarioCache hit rate
Single long prompt, sent twice back to back98.7% (18,688 of 18,937 tokens)
Agent / editor traffic over a day90.7% (390M of 430M tokens)

The first row is the best case and shows the ceiling. The second is what a real mixed workload looks like. Design for the second number.

03Structuring prompts for hits

Because matching is prefix-based, order your prompt from most stable to least stable:

[ system instructions  ]   stable, identical every call
[ tool / function specs ]   stable
[ retrieved documents   ]   stable within a session
[ conversation history  ]   grows by appending only
[ the new user message  ]   changes every call

Three habits follow directly:

04What it is worth

Take a 100K-token context sent ten times in a session, with 200 output tokens per turn. On the official off-peak rate (input $0.15/M on a miss, $0.003/M on a hit):

CaseInput cost for 10 calls
No caching — 10 misses × 0.1M × $0.15/M$0.150
Caching — 1 miss ($0.015) + 9 hits (9 × 0.1M × $0.003/M)$0.0177

That is an 8.5× reduction on the input side, from the second call onward.

The rule of thumb: the saving is roughly 1 − (1 − h) × 0.02 of the naive input bill, where h is your hit rate — but only on the calls after the first. A single one-shot request never hits, so caching does nothing for it. This is why agent and editor traffic (long stable prefix, many turns) sees a far bigger saving than short chat traffic.

It also means a large prefix reused only twice is barely worth optimising for, while a modest prefix reused fifty times is worth a great deal. Optimise the reuse count, not the prefix size.

05FAQ

Do I have to enable caching?

No. Caching is applied upstream automatically based on prefix matching. You cannot turn it on or off through the API, and there is no cache parameter to set.

How long does a cache entry live?

It is managed by the upstream provider and is not guaranteed. Treat any hit as a bonus rather than something to depend on for cost planning.

Does the cache work across different API keys?

Assume not. Keep a given workload on one key if you care about hit rate.

Will caching reduce answer quality?

No. A cache hit returns the same computation, not a stored answer. The model still generates the response; only the input-side billing changes.

← All guides API reference
Start free

→Read next