Skip to main content

LLM Prompt Caching Calculator

Estimate token savings and cost reductions from LLM prompt caching with Anthropic Claude and OpenAI GPT-4.

✓ Anthropic & OpenAI caching ✓ Monthly savings estimate ✓ Breakeven analysis
1K100K

System prompt + tool definitions + static context

10010K

User messages + conversation history (per call)

504K
0%100%

Cost Per 1,000 Calls

Without caching $0.00
With caching $0.00
Savings per 1K calls $0.00

Monthly Projection

Monthly calls 0
Without caching $0.00
With caching $0.00
Monthly savings $0.00
Savings % 0%
Breakeven Analysis

Implementation Guide

Anthropic (Claude)
import anthropic
client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": "Your long system prompt here...",
        "cache_control": {"type": "ephemeral"}
    }],
    messages=[{"role": "user", "content": query}]
)
# cache_read_input_tokens in usage
OpenAI (GPT-4o)
from openai import OpenAI
client = OpenAI()

# Caching is AUTOMATIC for prompts > 1024 tokens
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": long_system_prompt},
        {"role": "user", "content": query}
    ]
)
# cached_tokens in usage.prompt_tokens_details
Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →

Frequently Asked Questions

What is prompt caching in LLMs?▼

Prompt caching lets you store and reuse a processed portion of your prompt (usually the system prompt or static context) across multiple API calls. Instead of re-processing thousands of tokens each time, the model reuses its cached KV (key-value) state. Anthropic charges 10% of the normal input price for cache read hits, and 125% for the initial cache write. OpenAI offers automatic caching at 50% discount for prompts over 1,024 tokens.

How much can prompt caching save?▼

Savings depend heavily on your system prompt length and cache hit rate. A 10,000-token system prompt with Claude 3.5 Sonnet normally costs $0.03 per call. With caching at 80% hit rate, the effective cost drops to about $0.006 per call — an 80% reduction. For high-volume applications (1M+ calls/day), this can translate to thousands of dollars monthly.

How does Anthropic prompt caching work?▼

To use Anthropic caching: add cache_control: {type: 'ephemeral'} to the system prompt content block. The first call writes to cache (costs 1.25x normal). Subsequent calls within the TTL (5 minutes, extendable by each use) pay 0.1x normal input price. Cache is per-prompt prefix — changing even one token invalidates the cache. You need Claude 3 Haiku, Sonnet, or Opus.

How does OpenAI prompt caching work?▼

OpenAI enables automatic prompt caching for prompts over 1,024 tokens. When the prefix of a prompt matches a recently used prompt, you're charged 50% of the normal input token price for those cached tokens. Unlike Anthropic, there's no explicit API call needed — OpenAI handles caching automatically. Available for GPT-4o, GPT-4o Mini, and o1 models.

What content is good to cache?▼

Best to cache: (1) Long system prompts with tool definitions, company policies, or knowledge bases. (2) Few-shot examples that rarely change. (3) Document context that's the same across many queries. (4) Conversation history for stateful applications. Worst to cache: dynamic content, user-specific data, or anything that changes per request. The static prefix must come before dynamic content.