Claude API · Caching, batches and tokens

Cache a large prompt

Add top-level cache_control to cache the last cacheable block. Repeated requests with the same prefix are much cheaper.

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    cache_control={"type": "ephemeral"},
    system=large_document_text,
    messages=[{"role": "user", "content": "Summarize the key points"}],
)

Official Claude API documentation

More caching, batches and tokens commands

All caching, batches and tokens commands · Claude API cheatsheet

Was this page helpful?