[All posts](https://hostlinku.com/en/blog)

Guides 3 min read

# How to tell when your prompt cache is working

Use a cold request, a repeated prefix, and a control run to find out how much input the endpoint actually reused.

By the Hostlinku team

On this page

A coding agent may send the same project instructions, tool definitions, and source files on several turns. Prompt caching can reuse work on that shared prefix. A quick response alone tells you very little about whether reuse happened. To check, keep the request conditions steady and compare token usage across a small set of runs.

## Run a cold, warm, and control request

1.  Choose one model, API dialect, and service mode. Build a stable prefix long enough for the model's cache rules. Use a fresh prefix for the cold run and put the changing question at the end.
2.  Repeat with the same prefix within the applicable retention window. Keep the tool list and its ordering stable, and send requests sequentially so the first response has finished before the second begins.
3.  Run a control with a change near the start of the prefix, leaving the total input size roughly the same. If the dialect accepts explicit cache breakpoints, keep the breakpoint placement consistent across all three runs.

Record the request ID, input and output counts, cache read and write counts, and time to first token. Chat Completions can report cache reads as `usage.prompt_tokens_details.cached_tokens`. Claude Messages reports `cache_read_input_tokens` and `cache_creation_input_tokens` separately. On Claude Messages, add both to `input_tokens` to calculate total input. [OpenAI prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) · [Claude prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching)

How to isolate cache reuse

Request structure

Warm runReuse the same prefix within the cache retention window. Change only the question.

What to compareCompare cached input tokens with the cold run.

Warm run · Illustrative token usage

**36,000** cached**4,000** uncached

Shaded cells mark the shared request blocks. The bar shows how much of a 40,000-token input a warm request could reuse.

## Read the counters alongside the bill

In an illustrative 40,000-token request, a warm response that reports 36,000 cached input tokens served 90% of the input from cache. The remaining input and the output still contribute to the bill. Use the actual rates for uncached input, cache reads, writes where billed, and output. Over a repeated workflow, a warm-read discount has to be weighed against the cost of filling the cache.

If the counters are absent, save that as missing data and check the endpoint's usage format and the request log. If every warm run reports zero, check the minimum prefix length, retention window, and any dynamic fields near the start of the request. A warm series with positive reads and a control that loses those reads gives you a stronger result than a single fast request.

## Sources

1.  [Prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) · OpenAI
2.  [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) · Claude API Documentation

## More to read

-   [
    
    Guides · 4 min read
    
    Connect OpenCode to the models your key can use
    
    
    
    ](https://hostlinku.com/en/blog/open-code-catalog-by-key)
-   [
    
    Guides · 3 min read
    
    Trace an API charge back to the request
    
    
    
    ](https://hostlinku.com/en/blog/trace-api-usage-and-cost)
