docs

Prompt caching

Agents and chat apps resend the same long context on every turn: the system prompt, tool definitions, earlier messages, files. Model vendors keep the processed start of a prompt for a few minutes, and when the next request starts with exactly the same text they reuse it instead of reading it again. Those reused tokens are cached input and cost much less than fresh input.

Reads and writes

Token typeWhat it isBilled at
Fresh inputInput the model reads in fullinput_per_mtok
Cache readInput served from the prompt cachecached_input_per_mtok
Cache writeInput written to the cache so the next request can read it (Claude, Gemini explicit caching)cache_write_per_mtok
OutputWhat the model writes backoutput_per_mtok

Cached-read and cache-write prices follow the vendor's own ratio to its input price. Your discount applies to input, output and cache writes alike: if a model is 40 % off for you, they are all 40 % off. On most models cache reads get the same discount; on some they get a smaller one. The model page always shows the cached price you actually pay, and cached_discount_bps in GET /v1/models gives the discount on cache reads beside discount_bps. A model without a cached price on its page bills cached tokens at the input price.

Typical vendor ratios, as a guide (the model page has the exact prices):

VendorCache readCache write
Anthropic (Claude)~10 % of input~125 % of input (5-minute cache)
OpenAI10–50 % of inputnone: caching is automatic
Google (Gemini)~10–25 % of inputnone for automatic caching
DeepSeek~2–10 % of inputnone

Which models cache on their own

  • Automatic — OpenAI, DeepSeek, Qwen, GLM, Kimi and Gemini's implicit cache. Send the same prefix again within a few minutes and the repeat is read from the cache. Nothing to add to your request.
  • Opt-in: Claude — Anthropic caches only what you mark with cache_control. Without it, a repeated prompt is billed as fresh input every time.
json
{
  "model": "anthropic/claude-sonnet-5",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "<your long, stable context here>", "cache_control": { "type": "ephemeral" } },
        { "type": "text", "text": "The question for this turn" }
      ]
    }
  ]
}

The first request writes the marked prefix to the cache (billed at the cache-write price); repeats within about five minutes read it (billed at the cache-read price), and each read keeps the cache alive. Put the stable part first and the changing part last: the cache matches from the start of the prompt, byte for byte. Very short prompts (roughly under 1,024 tokens) are not cached. Claude Code, Cline, Roo Code and most coding agents add cache_control for you.

Where you see it

  • In the response — usage.prompt_tokens_details.cached_tokens (read from the cache) and usage.prompt_tokens_details.cache_write_tokens (written to it); both are part of prompt_tokens. usage.x_llm_cost_micro is the charge with each part at its own price.
  • Request detail (dashboard → Requests, and the Playground's This turn) — fresh input, cache read, cache write and output, each with its token count and what it cost, and the total.
  • Usage — the share of input that came from the cache, and a tokens-per-day chart split into fresh, cache read, cache write and output.

Worked example

anthropic/claude-sonnet-5 at a list price of $2.00 input, $0.20 cache read, $2.50 cache write and $10.00 output per 1M tokens, with a 42 % discount. A coding agent sends a 100,000-token context, then repeats it:

text
turn 1  write 100,000 × $2.50 /1M = $0.2500  → after 42 % off: $0.1450
turn 2  read  100,000 × $0.20 /1M = $0.0200  → after 42 % off: $0.0116
without caching, every turn:       $0.2000  → after 42 % off: $0.1160

From the second turn on, the cached context costs a tenth of the uncached one.