How Caching Works
Caching operates on prefix matching: the system stores processed tokens and reuses them when subsequent requests start with the same content. Consider a chatbot with a 2,000-token system prompt:1
Request 1
System prompt (2,000 tokens) + user message (50 tokens)Processed: 2,050 tokens · From cache: 0 tokensPrefix written to cache.
2
Request 2
System prompt (2,000 tokens) + user message (80 tokens)Processed: 80 tokens · From cache: 2,000 tokens
3
Request 3
System prompt (2,000 tokens) + user message (120 tokens)Processed: 120 tokens · From cache: 2,000 tokens
Supported Models and Pricing
Loading…
Claude Opus 4.5 charges a premium rate for cache writes ($7.50/1M tokens vs $6.00 for regular input). The first request populating the cache costs more, but subsequent cache hits save 90%. Other models don’t charge extra for cache writes.
Provider-Specific Behavior
Venice normalizes caching across providers. For most models, caching is automatic. Just send your requests and check the response for cache statistics. Claude requires explicit cache markers at the protocol level, but Venice adds these automatically for system prompts and conversation history. Caching behavior is ultimately controlled by each provider and may change, so check provider docs for the latest details.Claude Opus 4.5 (Anthropic)
Claude requires explicit cache breakpoints at the protocol level. Venice handles this automatically:- System prompts are cached automatically
- Conversation history is cached by placing a breakpoint on the second-to-last user message
Additional details:
- Up to 4 breakpoints per request: The system uses the longest matching prefix
- Cache key is byte-exact: Whitespace changes, different image encodings, or reordered tools break cache hits
- Cache-aware rate limits: Cached tokens don’t count against your ITPM limit, enabling higher effective throughput
- 25% write premium: First request costs more, but 90% savings on subsequent reads
Manual cache control
For special cases like caching a large document on the first turn, you can add explicit breakpoints:All Other Models
Caching is automatic. No special parameters needed. Just ensure your prompts exceed ~1,024 tokens and useprompt_cache_key for consistent routing.
Request Parameters
prompt_cache_key
For conversations or agentic workflows, use a consistentprompt_cache_key to improve cache hit rates:
Response Fields
The responseusage object includes cache statistics:
Billing breakdown (using Claude Opus 4.5 as example):
- 5000 cached tokens × $0.60/1M = $0.003
- 500 uncached tokens × $6.00/1M = $0.003
- Total: $0.006 (vs $0.033 without caching, 82% savings)
Best Practices
Structure prompts for caching
Place static content at the beginning, dynamic content at the end. Good structure
Bad structure
Keep prefixes byte-identical
Cache keys are computed from exact byte sequences. Even trivial differences break cache hits:- Different whitespace or newlines
- Timestamps or request IDs in prompts
- Randomized few-shot example ordering
- Different formatting of the same content
Meet minimum token thresholds
If your prompts are below the minimum (typically 1,024 tokens), caching won’t activate. For small prompts, consider:- Adding more context or examples to reach the threshold
- Bundling multiple small requests into batched prompts
- Accepting that caching won’t apply for simple queries
Use prompt_cache_key for conversations
For ongoing conversations, set a consistentprompt_cache_key:
Monitor cache performance
Track these metrics:- Cache hit rate:
cached_tokens / prompt_tokens - Cost savings: Compare actual cost vs. uncached cost
- Latency reduction: Time-to-first-token with vs. without cache hits
cached_tokens is consistently 0:
- Prompts may be below minimum token threshold
- Prompts may be changing between requests
- Requests may be hitting different servers (use
prompt_cache_key) - Cache may have expired (requests too infrequent)
Consider cache economics
Claude Opus 4.5 cache write premium: First request costs 25% more, but 90% savings on subsequent reads.Cache Lifetime
Caches expire after a period of inactivity (typically 5-10 minutes). This means:Caching with Tools and Functions
Function definitions can be cached along with system prompts:Caching with Images and Documents
For vision models, images can be included in cached content:Troubleshooting
cached_tokens is always 0
cached_tokens is always 0
cache_creation_input_tokens on every request
cache_creation_input_tokens on every request
Higher costs than expected
Higher costs than expected