LLM Prompt Caching Calculator
Estimate token savings and cost reductions from LLM prompt caching with Anthropic Claude and OpenAI GPT-4.
System prompt + tool definitions + static context
User messages + conversation history (per call)
Cost Per 1,000 Calls
Monthly Projection
Implementation Guide
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 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 Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
JSON Formatter & Validator
Format, beautify, and validate JSON online. Paste your JSON to instantly pretty-print it with 2-space, 4-space, or tab indentation. Minify JSON too. Free, runs in your browser.
Open free tool →
Regex Tester
Free regex tester. Test regular expressions against multiple strings with expected match/no-match assertions — see instant pass/fail results. Built-in presets for email, URL, IPv4, and phone. Pro: unl
Open free tool →
Base64 Encoder & Decoder
Free Base64 Encoder & Decoder. Convert text, images, and any file to Base64 and back. Supports URL-safe Base64, image data URIs, and file download from Base64. Runs 100% in your browser — no data sent
Open free tool →
More Free Tools
Related Articles
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
Best AI Code Review Tools 2026: CodeRabbit, Sourcery, DeepCode & Bito Compared
Compare top AI code review tools for 2026: CodeRabbit, Sourcery, DeepCode, and Bito. Features, pricing, GitHub/GitLab integration, and choosing the right tool for your team.
AI Code Review Tools 2026: GitHub Copilot, CodeRabbit, Qodo Merge Ranked
Compare AI code review tools for 2026: GitHub Copilot code review, CodeRabbit, Qodo Merge, Sourcery, and PR-Agent. Pricing, accuracy, and GitHub integration.
AI Coding Tools Comparison 2026: GitHub Copilot vs Cursor vs Windsurf vs Cline
Comprehensive comparison of the best AI coding tools in 2026: GitHub Copilot, Cursor, Windsurf, and Cline. Pricing, features, model support, and real-world benchmarks.
AI Pair Programming in 2026: GitHub Copilot vs Cursor vs Claude Code
Master AI pair programming in 2026. Compare GitHub Copilot, Cursor, and Claude Code for autocomplete, chat, and agentic workflows. Includes setup guides and productivity tips.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
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.