🤖 AI Tools
· 3 min read
Last updated on

Prompt Caching Explained — Save Up to 90% on LLM API Costs


Prompt caching can lower the cost of repeated prompt prefixes, but savings depend on the model, hit rate, lifetime and write charges. Put reusable content first, then verify the selected provider’s controls rather than assuming every cache is automatic or priced identically.

How it works

When you send a request, the API provider checks if the first N tokens match a recently cached prompt prefix. If they do, those tokens are served from cache at a massive discount.

ProviderCache discountCache lifetimeMin cacheable
Anthropic90% off input5 minutes1,024 tokens
OpenAIModel-specific cached-input rateGPT-5.6+: 30m or 12h; earlier models use separate retention settings1,024 visible input tokens for GPT-5.6+
Google75% off inputConfigurable32,768 tokens

When it saves money

Prompt caching helps when you send the same prefix repeatedly:

System prompts — Your 2K-token system prompt is identical across all requests. With caching, you pay full price once, then 90% less for the next 5 minutes of requests.

Few-shot examples — If you include 10 examples in every prompt, those examples get cached.

Large context documents — Sending the same codebase or documentation to every request? Cache it.

Conversation history — Each new message in a conversation shares the entire previous history as a prefix.

When it doesn’t help

  • Unique prompts — If every request is completely different, nothing gets cached
  • Low reuse — Check the model’s lifetime and write cost; a longer TTL is not automatically cheaper
  • Short prompts — Prefixes below the selected model’s minimum are not eligible

Implementation

Anthropic (Claude)

Caching is automatic for the first 1,024+ tokens. Structure your prompt so the static part comes first:

response = client.messages.create(
    model="claude-sonnet-4.6",
    system="You are a senior developer...",  # This gets cached
    messages=[
        {"role": "user", "content": large_codebase},  # This gets cached too
        {"role": "user", "content": "Fix the bug in auth.ts"}  # Only this is new
    ]
)

OpenAI

For GPT-5.6 and later, OpenAI documents Responses API prompt_cache_options.ttl: 30m (default) or 12h. Total write rates are 1.25x or 2.5x ordinary input; reads use model-specific prices. Put reusable context first and budget writes separately.

response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[
        {"role": "system", "content": long_system_prompt},  # Older-model example
        {"role": "user", "content": specific_question}       # Full price
    ]
)

The example above is an earlier-model request. Those models use supported prompt_cache_retention settings (in_memory or 24h), not the newer TTL parameter. Support varies by model. Cache lifetime is not a data-deletion deadline.

Real savings example

An AI coding agent sending 100 requests/hour with a 5K-token system prompt:

Without cachingWith caching
System prompt cost5K × 100 × $15/1M = $7.50/hr5K × 1 × $15/1M + 5K × 99 × $1.50/1M = $0.82/hr
Monthly savings—~$4,800/month

That’s why our AI race agents use structured prompts with static identity files loaded first — the system prompt and IDENTITY.md get cached across runs.

Combine with model routing

The biggest savings come from combining caching with model routing:

  1. Route simple tasks to DeepSeek ($0.27/1M) — no caching needed, already cheap
  2. Route complex tasks to Claude with caching — 90% off the system prompt
  3. Use local models for autocomplete — free

This combination typically achieves 70-85% cost reduction vs naive Claude-for-everything.

FAQ

What is prompt caching?

Prompt caching is when an API provider stores the processed representation of the beginning of your prompt so it doesn’t need to be recomputed on subsequent requests. If your next request starts with the same tokens, those cached tokens are served at 50-90% off the normal input price. It’s automatic on most providers — you just need to structure prompts with static content first.

Does prompt caching affect quality?

No. Prompt caching only skips redundant computation — the model produces identical results whether tokens are cached or freshly processed. The output quality, reasoning, and behavior are exactly the same. Caching is purely a cost and speed optimization with no impact on model performance.

Which providers support it?

Anthropic, OpenAI and Google support prompt caching, but model-specific minimums, write fees and lifetimes differ. For current OpenAI models use the version-specific controls above rather than assuming a fixed 50% discount or a universal 5-minute lifetime. Verify the selected provider’s current documentation before budgeting.

Related: How to Reduce LLM API Costs by 70% · OpenRouter Complete Guide · AI Coding Tools Pricing 2026