AI / Claude Models Basics Interview Questions
What is prompt caching and how does it reduce costs when using Claude?
Prompt caching allows Anthropic to store a copy of a prompt prefix (such as a long system prompt, documentation, or conversation history) so that subsequent requests reusing that prefix are billed at a much lower rate than re-sending it fresh each time.
| Token type | Cost vs standard input |
|---|---|
| Cache write | ~25% more expensive (one-time cost to store the prefix) |
| Cache read (hit) | ~90% cheaper than standard input tokens |
| Standard input (miss) | Full input price |
# Example: using prompt caching with a long system prompt message = client.messages.create( model="claude-opus-4-8", max_tokens=1024, system=[ { "type": "text", "text": "You are an expert assistant...[5000 token system prompt]...", "cache_control": {"type": "ephemeral"} # mark this prefix for caching } ], messages=[{"role": "user", "content": "What is the main point of section 3?"}] )
When to use prompt caching:
- Long system prompts reused across many requests
- Large reference documents (codebases, manuals, books) that are constant across a session
- Long conversation histories in multi-turn applications
- Few-shot example sets provided in every request
Cache entries expire after a period of inactivity (5 minutes by default; a 1-hour TTL beta is available). The cache is per-organisation, not per-user.
More Related questions...