{"slug": "claude-prompt-caching-how-to-cut-api-costs-2026", "title": "Claude Prompt Caching: How to Cut API Costs (2026)", "summary": "Anthropic's prompt caching feature reduces API costs by up to 90% by allowing Claude to reuse processed prompt prefixes across requests instead of reprocessing them. A RAG chatbot sending a 10,000-token context block 100 times daily would cost $3.00 without caching but only about $0.33 with caching, according to a developer's analysis. The feature works by marking cache breakpoints in system prompts, tool definitions, or document context blocks, with cached tokens expiring after five minutes.", "body_md": "Originally published at\n\n[kalyna.pro]\n\nIf your app sends the same large system prompt, tool definitions, or document context on every request, you're paying full price to re-process those tokens every single time. **Prompt caching** lets Claude reuse the processed representation of a prompt prefix across requests — cache hits cost **90% less** than normal input tokens. This guide covers how caching actually works, the pricing math for writes vs reads, where to place cache breakpoints, and worked cost examples for RAG apps and agents.\n\n```\npip install anthropic\n```\n\nSee the [Claude API Tutorial](https://kalyna.pro/claude-api-tutorial/) if you're new to the Messages API, and [Claude API Pricing Explained](https://kalyna.pro/claude-api-cost/) for base per-model pricing.\n\nCaching works on **prefixes**. A request is processed top to bottom — system prompt, then tool definitions, then messages. You mark a cache **breakpoint** by adding `\"cache_control\": {\"type\": \"ephemeral\"}`\n\nto a content block. Everything from the start of the prompt up to and including that block is cached as a unit.\n\nOn the next request, if the prefix up to a breakpoint is byte-for-byte identical to a cached prefix, Claude reads the cached version instead of reprocessing it — you only pay full price for whatever comes after the last matching breakpoint. If anything before a breakpoint changes, that cache entry misses and gets rewritten.\n\nUsing **Claude Sonnet 4.6** ($3 / $15 per 1M tokens, input/output) as an example:\n\nThe same multipliers apply to every model's base price — for Haiku 4.5 ($0.25 / $1.25 per 1M) a cache read costs $0.025 / 1M; for Opus 4.7 ($15 / $75 per 1M) it costs $1.50 / 1M.\n\nA RAG chatbot sends a 10,000-token retrieved-context block as the cached prefix, handling 100 requests/day at a steady pace.\n\n**Without caching:** 100 × 10,000 × $3.00/1M = **$3.00/day**\n\n**With caching:** first request writes the cache (10,000 × $3.75/1M = $0.0375). The remaining 99 read from cache (99 × 10,000 × $0.30/1M = $0.297). Total: **≈ $0.33/day** — about an 89% reduction, compounding with every extra request.\n\n``` python\nfrom anthropic import Anthropic\n\nclient = Anthropic()\n\nLARGE_SYSTEM_PROMPT = open(\"knowledge_base.md\").read()  # 8,000+ tokens\n\nresponse = client.messages.create(\n    model=\"claude-sonnet-4-6\",\n    max_tokens=1024,\n    system=[\n        {\n            \"type\": \"text\",\n            \"text\": LARGE_SYSTEM_PROMPT,\n            \"cache_control\": {\"type\": \"ephemeral\"},\n        }\n    ],\n    messages=[{\"role\": \"user\", \"content\": \"Summarize the refund policy.\"}],\n)\n\nprint(response.usage)\n# Usage(input_tokens=12, cache_creation_input_tokens=8000, cache_read_input_tokens=0, ...)\n```\n\nThe first call writes the cache. Send the same system prompt again within 5 minutes, and `cache_read_input_tokens=8000`\n\n, `cache_creation_input_tokens=0`\n\n— those tokens now cost 90% less.\n\nTool schemas count as input tokens on every call, including every step of a [tool-use loop](https://kalyna.pro/claude-api-function-calling/). Cache them by adding `cache_control`\n\nto the last tool in the list:\n\n```\ntools = [\n    {\"name\": \"get_stock_price\", \"description\": \"...\", \"input_schema\": {...}},\n    {\"name\": \"get_exchange_rate\", \"description\": \"...\", \"input_schema\": {...}},\n    {\n        \"name\": \"get_current_time\",\n        \"description\": \"Get the current date and time in UTC.\",\n        \"input_schema\": {\"type\": \"object\", \"properties\": {}},\n        \"cache_control\": {\"type\": \"ephemeral\"},\n    },\n]\n```\n\nThis caches all tool definitions as one prefix block — high leverage for agents, since `tools`\n\nis resent unchanged on every loop step.\n\n```\nresponse = client.messages.create(\n    model=\"claude-sonnet-4-6\",\n    max_tokens=1024,\n    messages=[\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                    \"type\": \"text\",\n                    \"text\": f\"<document>{long_document}</document>\",\n                    \"cache_control\": {\"type\": \"ephemeral\"},\n                },\n                {\n                    \"type\": \"text\",\n                    \"text\": \"What are the payment terms in section 4?\",\n                },\n            ],\n        }\n    ],\n)\n```\n\nFollow-up questions about the same document, sent within 5 minutes, only pay full price for the new question.\n\n```\n{\n    \"type\": \"text\",\n    \"text\": LARGE_SYSTEM_PROMPT,\n    \"cache_control\": {\"type\": \"ephemeral\", \"ttl\": \"1h\"},\n}\n```\n\nThe 1-hour cache costs 2× base to write (vs 1.25× for 5-minute), reads are still 0.1×. It pays off once a cached prefix is reused at least twice within the hour. For traffic denser than every 5 minutes, the default TTL is usually cheaper.\n\nUp to 4 breakpoints per request:\n\n```\nsystem=[\n    {\n        \"type\": \"text\",\n        \"text\": STATIC_INSTRUCTIONS,           # rarely changes — shared across all users\n        \"cache_control\": {\"type\": \"ephemeral\"},\n    },\n    {\n        \"type\": \"text\",\n        \"text\": USER_PROFILE_CONTEXT,          # changes per user\n        \"cache_control\": {\"type\": \"ephemeral\"},\n    },\n]\n```\n\nClaude checks for the longest matching cached prefix. Ordering from least-to-most volatile means a change to `USER_PROFILE_CONTEXT`\n\ndoesn't invalidate `STATIC_INSTRUCTIONS`\n\n.\n\n`tools`\n\narray for agents`usage.cache_read_input_tokens`\n\nvs `cache_creation_input_tokens`\n\n— aim for 90%+ hit rate on steady traffic`cache_control: {\"type\": \"ephemeral\"}`\n\n`\"ttl\": \"1h\"`\n\nfor sparser trafficFurther reading:", "url": "https://wpnews.pro/news/claude-prompt-caching-how-to-cut-api-costs-2026", "canonical_source": "https://dev.to/kalyna_pro/claude-prompt-caching-how-to-cut-api-costs-2026-484m", "published_at": "2026-06-12 13:06:29+00:00", "updated_at": "2026-06-12 13:41:38.165956+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "ai-infrastructure", "ai-products", "generative-ai"], "entities": ["Claude", "Anthropic", "Sonnet 4.6", "kalyna.pro"], "alternates": {"html": "https://wpnews.pro/news/claude-prompt-caching-how-to-cut-api-costs-2026", "markdown": "https://wpnews.pro/news/claude-prompt-caching-how-to-cut-api-costs-2026.md", "text": "https://wpnews.pro/news/claude-prompt-caching-how-to-cut-api-costs-2026.txt", "jsonld": "https://wpnews.pro/news/claude-prompt-caching-how-to-cut-api-costs-2026.jsonld"}}