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
Pricing
Most text models support caching. Each model’s cache read and cache write prices are on its page under Text models, and inmodel_spec.pricing.cache_input and model_spec.pricing.cache_write in the List Models response.
Some models, including Claude and GPT-5.6 and later, charge more for cache writes than for regular input. The first request that fills the cache costs more, and later cache hits are billed at the cheaper cache read price.
model_spec.pricing.cache_write_1h. On those models, cache_write covers five-minute writes and cache_write_1h covers one-hour 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. A few providers only cache content marked withcache_control, and Venice adds those markers for you.
Caching behavior is ultimately controlled by each provider and may change, so check provider docs for the latest details.
Cache read prices vary by model, from a few percent of the input price to about half of it. Check
model_spec.pricing.cache_input for the model you use.
Claude (Anthropic)
Claude requires explicit cache breakpoints at the protocol level. Venice handles this automatically:- System prompt: Venice marks the end of the system prompt. Leading
developermessages are sent to Claude as part of the system prompt, so they are cached with it. - Conversation history: Venice marks your previous assistant reply, so everything before the newest user message is read from cache.
- Tool loops: when a request ends with tool results, Venice marks the newest tool result instead. Each round is written to the cache once and read on the next round.
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 writes cost more than input: 1.25x the input price for five-minute writes and 2x for one-hour writes. Cache reads cost 10% of the input price on most Claude models, 5% on Claude Opus 5.5 and Sonnet 5.5, and 2.5% on Claude Fable 5.1 and 5.2.
Manual cache control
For special cases like caching a large document on the first turn, you can add explicit breakpoints:How your markers combine with Venice’s
- A request can have at most four cache breakpoints. If you send more, Venice keeps the last four, which cover the longest prefixes.
- Venice adds its automatic markers only in the slots you leave free, and doesn’t add one to a system prompt you already marked.
- Venice keeps
cache_controlon system and user content blocks, on tool messages (on the message itself or inside its content), and on Anthropic-styletool_resultblocks. - Claude accepts
ttlvalues of"5m"(the default) and"1h", and requires one-hour blocks to come before five-minute blocks, counting from the system prompt. Venice’s automatic markers follow your TTLs, and Venice drops markers on tool results that break either rule. Other blocks that break them make Claude reject the request.
One-hour cache lifetime
By default, Claude cache entries last five minutes. To keep a block cached for an hour, setttl to "1h" in its cache_control object:
ttl accepts "5m" (the default) or "1h". One-hour writes are billed at the model’s cache_write_1h price when its pricing lists one (Anthropic charges 2x the input price). The response reports them in prompt_tokens_details.cache_creation_1h_input_tokens.
Qwen and Gemini 3.x
Venice marks the end of the system prompt and the message before your newest user message, usually your previous assistant reply. On Qwen models hosted by Alibaba, it marks the newest tool result in tool loops. Markers you add inside system, user or assistant message content are passed through; markers on tool messages are not.All Other Models
Caching is automatic, and you don’t needcache_control. OpenAI’s GPT-5.6 and later models place their own breakpoint at the end of the latest message and keep cache entries for at least 30 minutes. Keep prompts above the minimum length and use prompt_cache_key for consistent routing.
Request Parameters
prompt_cache_key
For conversations or agentic workflows, use a consistent prompt_cache_key to improve cache hit rates:
Response Fields
The responseusage object includes cache statistics:
The cache write fields appear only when the request wrote to the cache.
Billing breakdown (using Claude Sonnet 5.5 as example):
- 5,000 cached tokens × $0.10/1M = $0.0005
- 500 uncached tokens × $2.00/1M = $0.001
- Total: $0.0015 (vs $0.011 without caching, 86% 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
Each model has a minimum prefix length below which nothing is cached, and no error is returned. On Claude it is 512 tokens for Opus 5.5, Opus 5, Sonnet 5.5, Fable 5, Fable 5.1, Fable 5.2 and Haiku 5.5, 1,024 for Opus 4.8, Sonnet 5 and Sonnet 4.6, 2,048 for Opus 4.7, and 4,096 for Opus 4.6 and Opus 4.5. OpenAI models need 1,024 tokens, and other providers typically need around 1,024. 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 consistent prompt_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 cache writes: a five-minute write costs 25% more than regular input, and a one-hour write costs twice as much. Reads then cost 10% of the input price or less.Cache Lifetime
Caches expire after a period of inactivity (typically 5-10 minutes). This means:
For Claude, you can extend a cache entry to one hour with a one-hour cache lifetime. OpenAI’s GPT-5.6 and later keep entries for at least 30 minutes. On earlier GPT models that support extended retention, set
prompt_cache_retention to "24h" to keep entries for up to 24 hours.
Caching with Tools and Functions
Function definitions can be cached along with system prompts:Tool loops
In an agentic loop, each request ends with the results of the previous tool calls. On Claude, and on Qwen models hosted by Alibaba, Venice places the automatic marker on the newest tool result, so each round is written to the cache once and read by the next round. You don’t need markers of your own. To mark a tool result yourself on Claude, setcache_control on the tool message or inside its content:
tool_result blocks inside a user message keep their cache_control too.
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