Skip to content

Docs / Prompt caching

Prompt caching

Exact repeats are answered from our cache and not charged. Provider-side prompt caching, where a model has it, is billed at the cached input price.

Get an API key

Two kinds of caching can lower what a request costs. They work separately.

Our response cache Provider prompt caching
What is reused The whole answer to an identical request The model’s work on a repeated prompt prefix
Price Free: not charged at all Cached input tokens at the cached input price; the rest at normal prices
Where Every model Only models whose provider offers it
How you see it x-yunshu-cache: hit Cached token counts in usage and in GET /v1/generation

Our response cache: exact repeats are free

When a request repeats an earlier one exactly, we return the earlier answer from cache. A cache hit is not charged and does not reach the model.

curl -i https://api.yunshurouter.com/v1/chat/completions \
  -H "Authorization: Bearer $YUNSHU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek-v4.1-flash", "messages": [{"role": "user", "content": "Capital of France?"}]}'
# Send it again: the second response has  x-yunshu-cache: hit
raw = client.chat.completions.with_raw_response.create(
    model="deepseek-v4.1-flash",
    messages=[{"role": "user", "content": "Capital of France?"}],
)
print(raw.headers.get("x-yunshu-cache"))  # "hit" or "miss"

What counts as the same request

All of these must match:

  • the organisation that sent it (keys in the same organisation share the cache; organisations never do)
  • the format (an OpenAI-format answer is never served to an Anthropic-format request)
  • the model
  • the system prompt and every message
  • max_tokens, the reasoning switch and the tool definitions
  • fields that change the answer’s shape, such as response_format, tool_choice, stop and logprobs

These fields are not part of the match, so changing them alone still gives a cache hit: temperature, top_p, top_k, seed, frequency_penalty, presence_penalty, user, metadata, store, service_tier, prompt_cache_key.

Only exact repeats are matched. A reworded question is a new request.

What a hit returns

  • The same body as the first answer, streamed or not, with tool calls and the stop reason exactly as first returned.
  • model names the model you called.
  • x-yunshu-cache: hit. GET /v1/generation shows cache_hit: true and a cost of 0.

When you need a fresh answer

There is no per-request switch to skip the cache today. Because temperature and seed are not part of the match, sending the same request again to get a different sample returns the cached answer. To get a new answer, change the request (for example, the messages or max_tokens).

Zero retention

If your organisation has zero retention switched on, nothing of yours is read from or written to the cache. Every request goes to the model and is charged.

Provider prompt caching

Some providers keep a repeated prompt prefix (a long system prompt, a document, earlier turns) and charge less for those input tokens the next time. Where a model’s provider does this:

  • Cached input tokens are billed at the model’s cached input price. GET /v1/models shows it as pricing.cached_input_per_million, and capabilities.prompt_caching is true when a cached price exists.
  • The cached token count is reported in:
    • Chat Completions: usage.prompt_tokens_details.cached_tokens
    • Messages: usage.cache_read_input_tokens
    • Responses: usage.input_tokens_details.cached_tokens
    • GET /v1/generation: tokens.cached_input

Counts appear only when the model reports them.

Tips

  • Put the parts that stay the same first (system prompt, tool definitions, reference documents) and the parts that change last.
  • On the Anthropic format, the system prompt is sent as one string, so cache_control markers on system blocks are not kept.
  • Whether a cache is shared across requests also depends on which route serves each request.

We make no claim about how much provider caching saves. Check tokens.cached_input on your own traffic.