Prompt Caching Mistake That Broke Our Cost Model
Prompt Caching Mistake That Broke Our Cost Model
I made a prompt caching mistake that tripled my Anthropic API costs in under 24 hours. I’m going to tell you exactly what I did wrong, what it cost, and the specific configuration change that fixed it — because this is the kind of thing tutorials skip and production systems surface immediately.
This is a Friday post, which means it’s about building and learning. No polished case study. Just what actually happened.
TL;DR
I assumed prompt caching was enabled by default for long system prompts. It is not. I was paying full input token rates on every call, including a 2,400-token system prompt that ran hundreds of times per day. Once I explicitly marked the cache breakpoint and validated cache hit rates via the API response headers, cost dropped by 63% overnight. The fix took twelve minutes. The mistake ran for nine days.
What Prompt Caching Is (and What I Got Wrong)
Anthropic’s prompt caching lets you designate a portion of your prompt — typically a long system prompt, a large document context, or a reusable instruction block — as cacheable. When the same prefix appears in subsequent requests, Anthropic charges you cache read rates instead of full input token rates. Cache read pricing is roughly 90% cheaper than standard input pricing at current rates.
The assumption I made — the wrong one — was that Anthropic automatically caches long, repeated prefixes the way some cloud infrastructure caches repeated requests. It does not. You have to explicitly mark where the cache breakpoint should be using the cache_control parameter in your messages array. If you don’t mark it, every call prices at full input token rates, no matter how often that same content appears.
I built a pipeline that runs a structured analysis task — taking a batch of inputs, passing each one through a Claude Haiku call with a detailed system prompt that included role context, output format requirements, and a set of grounding rules. That system prompt was 2,400 tokens. The pipeline ran approximately 400 calls per day during peak usage.
Nine days. 3,600 calls. 2,400 tokens of fully-priced system prompt on every single one.
The Exact Mistake
Here’s a simplified version of the original message structure I was using:
messages = [
{
"role": "user",
"content": f"{SYSTEM_PROMPT}\n\n---\n\nInput: {user_input}"
}
]
Two problems here. First, I was passing the system prompt as part of the user message rather than using Anthropic’s system parameter — a separate architectural issue. Second, and more relevant to the cost problem, I had no cache_control directive anywhere in the payload.
The corrected structure:
response = client.messages.create(
model="claude-haiku-20240307",
max_tokens=1024,
system=[
{
"type": "text",
"text": SYSTEM_PROMPT,
"cache_control": {"type": "ephemeral"}
}
],
messages=[
{
"role": "user",
"content": user_input
}
]
)
The cache_control: {"type": "ephemeral"} on the system prompt block tells Anthropic’s API to cache everything up to that breakpoint. Subsequent calls that share the same system prompt prefix hit the cache instead of re-processing the full token count.
What It Cost and What the Fix Returned
I won’t publish my exact monthly invoice, but I can give you the relative numbers.
Over the nine days before the fix, I averaged roughly $4.20/day on this pipeline. That seemed plausible to me for the volume, which is part of why I didn’t catch it immediately. I had no per-pipeline cost breakdown — just a single account total — so the signal was buried.
After implementing the cache breakpoint:
- Daily cost on the same pipeline: $1.55
- Cache hit rate (visible in
usage.cache_read_input_tokensin the API response): 91% - The remaining 9% were cold cache misses on first-call pipeline starts and occasional cache expiration
63% cost reduction. Running forward, that’s meaningful at any scale.
The other thing I changed: I added per-pipeline cost tracking by logging usage fields from every API response to a lightweight SQLite table. I now have actual visibility instead of a monthly surprise. This should have been there from day one.
Why I Missed This for Nine Days
A few compounding factors:
No cost alerting. I had not set a spend alert on the Anthropic account. I do now. Hard limit plus a soft alert at 70% of the limit. Takes two minutes to configure and I have no excuse for not having done it.
Plausible-looking numbers. $4/day sounds reasonable for a pipeline processing hundreds of AI calls. I wasn’t comparing it against what it should cost because I hadn’t done that math upfront. Now I estimate expected cost before deploying any new pipeline and set a baseline expectation before the first bill arrives.
Assumption over verification. I read about prompt caching during initial research, assumed I understood how it activated, and never went back to verify my implementation matched the documentation. This is a pattern I know from 25 years in enterprise security — assumptions about default behavior are where the gaps live. In IAM, we call it “assumed secure.” The failure mode is identical here.
Prompt Caching Security Considerations
One question worth addressing: is there a security angle to prompt caching?
Yes, and it’s worth a few sentences.
When you cache a prompt prefix, that cached content persists on Anthropic’s infrastructure for up to five minutes (ephemeral cache) or longer depending on cache tier. For most content — formatting rules, role definitions, generic grounding instructions — this is fine.
For anything that includes confidential business logic, client-identifying information, or system-specific context that shouldn’t persist, think carefully about what you’re marking as cacheable. The system prompt is the boundary. Keep cached content generic and reusable. Keep sensitive, request-specific context in the non-cached user message.
In a regulated environment, document what you’re caching and why. If you ever face a compliance inquiry about data handling with an AI vendor, knowing exactly what data entered a cache and for how long is the kind of answer that distinguishes a mature AI governance posture from a guess.
Key Takeaways
Prompt caching is not automatic. You must explicitly mark cache breakpoints using cache_control in your API payload. If you’re running repeated calls with long system prompts and you haven’t done this, check your usage logs today.
Validate with the response. The usage object in every Anthropic API response includes cache_creation_input_tokens and cache_read_input_tokens. If cache_read_input_tokens is zero across multiple calls with the same prompt, your cache is not hitting. This is your canary.
Separate system prompt from user message. Use the system parameter, not a concatenated user message. It’s the correct architectural pattern and it’s where cache_control applies cleanly.
Cost visibility is not optional. Log usage fields per call, per pipeline, per day. A monthly invoice with no granularity is not monitoring — it’s archaeology.
Estimate before you deploy. Run the math: calls per day × input tokens × price per token. Know your expected cost before the pipeline goes live. Compare actual to expected within the first 48 hours.
The mistake was avoidable. The fix was trivial. The gap between them was nine days of higher-than-necessary spend and no alerting to catch it. I’m publishing this because I know I’m not the only one who assumed caching “just works” — and the exact same failure mode applies to any LLM API with an explicit caching model.
Comments