New Tool Radar

AI Concepts

How to Check Prompt Cache Hit Rate from API Response Headers

Read cache usage from API responses to find out whether your prompt prefix is actually being reused, or silently reprocessed every time.

Schematic illustration with three step boxes: find the cache fields, log a week of calls, and fix the misses.

Providers report cache usage in the response: check the response headers for cache usage metrics to verify hits. A request that should hit the cache but does not is usually broken by one changing token in the prefix. Logging the hit rate turns a hope about caching into a number you can act on.

Before you start

An API provider that reports cache usage, and a log where you can record the cache fields per call.

Find the cache fields in the response

Open your provider’s API documentation and find where cache usage is reported: response headers, a usage object, or both. Note the field names for cached input tokens, cache creation tokens, and cache read tokens.

Make one test call with a long static prefix and read the fields: the first call should show cache creation, the second identical call should show a cache read.

Log a week of real calls

Log the cached token count and the total input token count for every call for a week. Compute the hit rate as cached tokens divided by total input tokens, per day and per request type.

Split the log by request type: a support bot and a report generator have different prefixes and different hit rates, and one average hides both.

Fix the misses you find

For the request types with the lowest hit rate, diff two consecutive requests and find the token that changes. Common causes are timestamps, user ids, reordered messages and per-request instructions.

Move the changing token after the static prefix or out of the prompt entirely, then re-measure the hit rate for that type.

Practice check: fictional Maple Corner support bot, one week, 7,000 calls

The table below is fictional practice material, worked out by hand from the stated hit rates. It is the expected result for the practice log, not a run of any API.

Request type Calls Hit rate Verdict
Support answers 5,000 96% Pass
Order lookups 1,500 88% Pass
Daily reports 500 41% Fail – prefix changes daily

Support answers hit the cache 96 percent of the time, but daily reports only 41 percent: the report prompt includes the date in the static part, which breaks the cache every day. Moving the date after the prefix is the fix.

Expected result. UNTESTED: the hit rates in the practice table are worked out by hand, not measured by running an API. Log the cache fields on your own calls for a week, compute the hit rate per request type, and fix the lowest one first.

Limits

  • A cache hit rate of 100 percent is not the goal: the goal is a high hit rate on the long static parts.
  • Cache fields differ by provider: read your provider’s documentation for the exact field names.

Sources

See all