Prompt Caching
Cache long prompt prefixes across requests to cut cost and latency.
Cache a long, repeated prompt prefix (system prompt, RAG documents, tool catalog, few-shot examples) so repeat requests pay a fraction of the input price. AnyRouter passes caching through on every upstream that supports it (Anthropic, OpenAI, DeepSeek, Gemini). If a chunk repeats in two or more requests within five minutes, cache it.
Anthropic
Mark blocks with cache_control. Cache reads cost 10% of the input price, writes 125%, and the TTL is 5 minutes.
const response = await client.messages.create({
model: "anthropic/claude-sonnet-4-6",
max_tokens: 1024,
system: [
{
type: "text",
text: LONG_SYSTEM_PROMPT,
cache_control: { type: "ephemeral" },
},
],
messages: [{ role: "user", content: "What's the policy on refunds?" }],
})OpenAI
Prompts of 1024 tokens or more are cached automatically. No request change is needed.
Check the result
Cached tokens appear in usage, and are billed at the provider's cache-read rate with no AnyRouter markup. Each model page shows standard and cache-read prices.
{
"usage": {
"prompt_tokens": 5840,
"completion_tokens": 120,
"total_tokens": 5960,
"prompt_tokens_details": {
"cached_tokens": 5800
}
}
}AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer