Skip to main content
Prompt caching stores processed input tokens so subsequent requests with identical prefixes can reuse them instead of reprocessing. This reduces latency on long prompts and cuts cost: cache reads are billed at a fraction of the input price, often 10% or less. Venice handles caching automatically for supported models, but understanding how each provider implements caching helps you maximize cache hit rates and minimize costs.

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
Total without caching: 2,050 + 2,080 + 2,120 = 6,250 tokens at full price Total with caching: 2,050 + 80 + 120 = 2,250 tokens at full price, 4,000 tokens at discounted rate
Caching only works on the prefix. Any change to the beginning of your prompt invalidates the cache for everything that follows. Always put static content (system prompt, documents, examples) before dynamic content (user messages).

Pricing

Most text models support caching. Each model’s cache read and cache write prices are on its page under Text models, and in model_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.
Models that price one-hour cache writes separately also list 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 with cache_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 developer messages 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.
This means your conversation history is read from cache, and only the latest turn is processed as new input: 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:
This ensures both the system prompt and document are cached from the first request. For typical conversations, you don’t need manual markers.

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_control on system and user content blocks, on tool messages (on the message itself or inside its content), and on Anthropic-style tool_result blocks.
  • Claude accepts ttl values 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, set ttl 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 need cache_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:
Venice keeps requests that share a key on the same provider and passes the key to providers that use it to route to a warm cache, such as OpenAI. If you don’t send one, Venice routes by your first user message and sends providers a key based on your account, so set your own when you run many conversations in parallel or rewrite earlier messages between turns. Use a session ID or conversation ID as the key.

Response Fields

The response usage 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:
This improves the likelihood that all turns hit the same server with warm cache.

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
If cached_tokens is consistently 0:
  1. Prompts may be below minimum token threshold
  2. Prompts may be changing between requests
  3. Requests may be hitting different servers (use prompt_cache_key)
  4. 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:
The tool definitions become part of the cached prefix. If you have many tools, this can significantly reduce per-request costs.

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, set cache_control on the tool message or inside its content:
Anthropic-style 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:
The image and initial context are cached, so follow-up questions about the same image don’t re-process it.

Troubleshooting