Skip to content

LLM prompt caching: check the usage before the bill

A cache counter describes reported token usage from the upstream model API. It does not, by itself, establish a hit rate, a saving, or an amount charged. Start with the request's protocol and complete usage object, separate ordinary input from recorded writes and reads, then compare that request with its billing record. Prompt caching is strictly an upstream model-API mechanism — there is no gateway-side prompt or answer cache — and this guide explains how to reconcile reported usage.

Identify the usage format first

The same word, input, can mean different things in different response formats. Read the fields from one completed request; do not combine a raw response, a dashboard summary, and a monthly total as if they were independent token buckets.

Identify the usage format first
SourceFields to inspectCounting rule
OpenAI-style Chat Completionsprompt_tokens; prompt_tokens_details.cached_tokensThe nested cached count is a subset of prompt_tokens. Do not add it to the prompt total.
OpenAI-style Responsesinput_tokens; input_tokens_details.cached_tokens; optional input_tokens_details.cache_write_tokens (and cache_write_tokens_details: ttl_30m_tokens, ttl_12h_tokens)All nested counters are already included in input_tokens, and ttl_30m_tokens plus ttl_12h_tokens sum to cache_write_tokens. Ordinary input equals full input minus the reported read and write portions. Preserve the complete usage object; a missing write field alone does not establish zero written input.
Native Anthropic Messagesinput_tokens; cache_creation_input_tokens (optional cache_creation: ephemeral_5m_input_tokens, ephemeral_1h_input_tokens); cache_read_input_tokensinput_tokens, cache_creation_input_tokens, and cache_read_input_tokens are separate input categories: ordinary input, newly written input, and read input. Their sum is the full request input; the optional cache_creation breakdown sums to cache_creation_input_tokens and must not be added again.
Normalized logs or SDK summariesinputTokens; cacheCreationInputTokens; cacheReadInputTokens; cachedTokensVerify the summary's field definitions first. cachedTokens and cacheReadInputTokens may represent the same recorded count, not two additional quantities.

Example 1: a nested count is already included

Hypothetical OpenAI-style usage, for arithmetic only—not a real request or bill. This example explicitly assumes zero written input. Of 10,000 input tokens, 6,000 are reported in the nested category and 4,000 remain ordinary input under that assumption. With 500 output tokens, total usage is 10,500. Adding 6,000 to prompt_tokens again would incorrectly report 16,000 input tokens.

illustrative-usage.json
{
  "prompt_tokens": 10000,
  "prompt_tokens_details": {
    "cached_tokens": 6000
  },
  "completion_tokens": 500,
  "total_tokens": 10500
}

Example 2: Responses includes both nested portions

Hypothetical Responses usage, for arithmetic only—not a real request or bill. The full input of 10,000 already includes 6,000 reported reads and 2,500 reported writes. Ordinary input is 10,000 − 6,000 − 2,500 = 1,500 tokens. The three non-overlapping portions sum to 10,000; with 500 output tokens, total usage remains 10,500. Neither nested portion should be added to input_tokens again.

illustrative-usage.json
{
  "input_tokens": 10000,
  "input_tokens_details": {
    "cached_tokens": 6000,
    "cache_write_tokens": 2500
  },
  "output_tokens": 500,
  "total_tokens": 10500
}

Example 3: separate categories must be summed once

Hypothetical native Anthropic usage, for arithmetic only—not a real request or bill. Full input is 2,000 + 3,000 + 5,000 = 10,000 tokens; adding 500 output tokens gives 10,500. Here input_tokens is the ordinary-input portion, unlike the inclusive input total in the first example.

illustrative-usage.json
{
  "input_tokens": 2000,
  "cache_creation_input_tokens": 3000,
  "cache_read_input_tokens": 5000,
  "output_tokens": 500
}

Why normalized statistics must not be added again

A reporting layer may already combine the three input categories into a full-input total while retaining its component counters for inspection. In that case, full input plus the write and read counters counts some tokens twice. Conversely, an ordinary-input-only field still needs those separate categories to reconstruct full input. A camelCase name or a dashboard label alone cannot distinguish these cases.

  • Keep the raw protocol fields and derived totals in separate columns.
  • Treat cachedTokens and cacheReadInputTokens as possible aliases; do not sum them without proof that they measure different usage.
  • Check output separately. A component breakdown explains a total; it is not extra usage to append to that total.

Upstream behavior and sticky fixed-priority routing

Prefix caching happens strictly inside the upstream model API, never on a gateway-side store. How a prefix qualifies depends on the vendor and model (all vendor docs checked 2026-11-26), while route stability determines whether consecutive turns reach the same upstream route:

  • Fixed-priority route order (/routing-methodology): requests for an exact model ID are not load-balanced across routes; each request starts at the top of the same gateway-managed priority order so consecutive turns of a session stay on the same upstream route rather than splitting across routes. Traffic moves to another route serving that same model only when the top route fails, cools down, or is demoted — a failover move can miss an existing upstream prefix and record a fresh write.
  • OpenAI (checked 2026-11-26): on GPT-5.6 and later (including GPT-6.2 Sol and GPT-6.2 Astra), the minimum cacheable prefix is 1,024 tokens, supporting both implicit and explicit breakpoints with a 30-minute default or 12-hour minimum lifetime on Responses. On GPT-6.2 Responses requests, top-level instructions are appended after input (beyond eligible breakpoints), so reusable instructions belong in an initial developer message inside input.
  • Anthropic (checked 2026-11-26): on the Messages API, callers opt in with top-level or block-level breakpoints (5-minute default or 1-hour lifetime). Prompts shorter than a model's minimum length (for example 4,096 tokens on Claude Opus 4.6, Opus 4.5, and Haiku 4.5, or 2,048 on Opus 4.7) run without caching and report 0 for both cache counters.
  • Google Gemini 4 Neon and Gemini 4 Hydrogen (checked 2026-11-26): per Google's model docs, Gemini 4 Neon (google/gemini-4-neon) and Gemini 4 Hydrogen (google/gemini-4-hydrogen) support implicit caching only — active by default on prompts of at least 4,096 tokens — and do not support explicit context caching (cachedContents / caches.create).

Reconcile one request in four steps

  • Match the request ID, exact model ID, time, and status. Each client or application retry starts a new request; internal provider fallback attempts may remain within the same request. Compare like with like before aggregating a session.
  • Capture the complete response usage object in your client. For streaming calls, use the final reported usage when available; an early event or a partial stream can be incomplete. Keep API keys and message bodies out of a billing support example.
  • Open Dashboard → Logs and locate that request. The detail view shows input and output tokens, the recorded cache-read count when positive, total time (plus time to first token on streamed requests that produced output), status, and the wallet charge — or the plan quota used on a plan-covered request, or a pending settlement label (for rolled-up wallet charges, tokens, and plan-covered requests by model or API key, check Dashboard → Usage). Logs does not display every raw response field (such as the cache-write count and its lifetime breakdown), so an absent row is not proof of zero usage.
  • Check the applicable model tariff and input-length tier. The live model page (/models) describes current rates; it cannot establish what applied to an older request. If counts or charges still disagree, provide the request ID, time, model and the minimal usage fragment for review rather than assuming the current catalog reproduces an old bill.

Separate token arithmetic from money

First establish the non-overlapping input categories, then multiply each count by its applicable rate and calculate output separately. Do not apply a single percentage to all of them. A request's token-cost calculation also differs from a final wallet debit when plan coverage or other billing terms apply.

  • A nonzero recorded read count does not establish a universal saving. Rates for each category can differ by model and request conditions; use the model detail page and the request record.
  • For a model with input-length tiers, full request input includes ordinary input plus distinct written and read input. Crossing the threshold selects the tier for the whole request, including its output; it is not a surcharge on only the excess tokens.
  • The cost calculator estimates a workload under its stated assumptions. It does not predict future cache behavior. The pricing methodology explains catalog rates and tier boundaries; request records explain a specific call.

FAQ

Should I add cached_tokens to prompt_tokens?

Not when cached_tokens is nested under prompt_tokens_details in an OpenAI-style response: it is already part of prompt_tokens. Native Anthropic Messages uses a different shape: ordinary input_tokens, cache_creation_input_tokens and cache_read_input_tokens are separate categories. Identify the format before adding anything.

How do I account for Responses cache_write_tokens?

In an OpenAI-style Responses usage object, input_tokens_details.cached_tokens and the optional input_tokens_details.cache_write_tokens are both included in input_tokens (and where cache_write_tokens_details reports ttl_30m_tokens and ttl_12h_tokens, those two sub-fields sum to cache_write_tokens). Ordinary input is the full input minus both reported portions. Do not subtract only the read count when writes are also reported, or add either portion to the full input again. A missing write field alone does not prove zero written input; confirm the complete usage format before calculating.

Does the gateway run its own prompt or answer cache?

No. Prompt caching happens strictly on the upstream model API — there is no gateway-side prompt or answer cache. To avoid breaking upstream prefix reuse unnecessarily, exact-model requests follow a fixed-priority route order rather than round-robin load balancing (/routing-methodology), switching routes only if the primary route fails, cools down, or is demoted.

Does a positive cache counter prove a discount or the amount charged?

No. It establishes a reported usage category, not a universal price or saving. Reconcile that category with the applicable model tariff, request conditions, and the request's billing record (wallet charge or plan quota used in Dashboard → Logs). Do not infer a fixed percentage or future hit rate from one counter.

Can I add cachedTokens and cacheReadInputTokens?

Not necessarily. A normalized response can expose the same read count under both names. Do not sum the two; inspect the raw usage format and the summary's definitions. Also confirm whether its input total already includes that count.

Does recorded read input count toward a long-context tier?

Tier selection uses the full request input, including ordinary input and distinct written and read input. For an inclusive input total, do not add its breakdown again. A threshold is crossed only when that full total is strictly greater than the stated boundary, and the selected tier applies to the whole request.

Does this guide promise caching support for every model?

No. This is a guide to interpreting reported usage and checking a bill. It does not establish request-parameter support, shared cached answers, a retention duration, cache availability, a hit rate, or a fixed saving. Consult the protocol documentation and the actual response for the model you use.