Claude API · Caching, batches and tokens
Check that caching works
If cache_read_input_tokens stays zero across repeated requests, something in the prefix changes every time, such as a timestamp.
print(response.usage.cache_creation_input_tokens) # written to the cache
print(response.usage.cache_read_input_tokens) # served from the cache
print(response.usage.input_tokens) # not cached
Official Claude API documentation
More caching, batches and tokens commands
All caching, batches and tokens commands · Claude API cheatsheet