Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosGoogle Chrome: Unfinished Projects: Solange’s Public Sculpture(21.09.2026 um 17:02 Uhr)
Windows Tipps & SecurityBlurry or pixelated video in Microsoft Teams(21.09.2026 um 14:34 Uhr)
Sicherheitslücken (CVE)USN-8791-1: Ghostscript vulnerability(21.09.2026 um 14:51 Uhr)
Sicherheitslücken (CVE)USN-8792-1: Memcached vulnerability(21.09.2026 um 15:02 Uhr)
Sichere ProgrammierungI stopped rewriting the same Electron boilerplate — so I packaged it(21.09.2026 um 17:28 Uhr)
YouTube Security VideosGoogle Chrome: Unfinished Projects: Solange’s Public Sculpture(21.09.2026 um 17:02 Uhr)
Windows Tipps & SecurityBlurry or pixelated video in Microsoft Teams(21.09.2026 um 14:34 Uhr)
Sicherheitslücken (CVE)USN-8791-1: Ghostscript vulnerability(21.09.2026 um 14:51 Uhr)
Sicherheitslücken (CVE)USN-8792-1: Memcached vulnerability(21.09.2026 um 15:02 Uhr)
Sichere ProgrammierungI stopped rewriting the same Electron boilerplate — so I packaged it(21.09.2026 um 17:28 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Prompt Caching Cut My Claude Bill by 80%: The Mistakes That Were Costing Me

I was paying full price for input tokens I was sending over and over. A large system prompt, a fixed tool list, the same reference docs on every request. Prompt caching should have made those cheap, except I had three silent bugs that…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

I was paying full price for input tokens I was sending over and over. A large system prompt, a fixed tool list, the same reference docs on every request. Prompt caching should have made those cheap, except I had three silent bugs that meant nothing was actually caching. Here is what I found when I finally checked the numbers, and how I got my hit rate from zero to consistent.






The one rule that explains everything



Prompt caching is a prefix match. Any byte change anywhere in the prefix invalidates everything after it. The cache key is the exact bytes of the rendered prompt up to each breakpoint.



Render order is fixed: tools, then system, then messages. So your most stable content has to physically come first, and anything that changes per request has to come last. Get the ordering right and caching mostly works for free. Get it wrong and no amount of cache_control markers will save you.






How I knew it was broken



The response usage object tells you the truth:




console.log(response.usage.cache_creation_input_tokens); // written to cache (~1.25x cost)
console.log(response.usage.cache_read_input_tokens); // served from cache (~0.1x cost)
console.log(response.usage.input_tokens); // full price, uncached






I ran the same request twice and cache_read_input_tokens was zero both times. If the prefix were identical, the second request should have read the cache. Zero reads means a silent invalidator was changing my prefix between requests.






Mistake 1: a timestamp in the system prompt



This was the big one:




// WRONG: the date changes every request, so the prefix is never stable
const system = `You are a security auditor. Current date: ${new Date().toISOString()}.`;






The date is at the front of the prefix, so it invalidated everything. I did not even need the timestamp in the system prompt. I moved it into the user message, which sits after the cached prefix and invalidates nothing before it.






Mistake 2: non-deterministic JSON



I was serializing a config object into the system prompt without sorting keys:




// WRONG: key order can vary, changing the bytes
const system = `Config: ${JSON.stringify(config)}`;
// RIGHT
const system = `Config: ${JSON.stringify(config, Object.keys(config).sort())}`;






Same data, different bytes, different cache key. JavaScript does not guarantee object key order across all code paths, and iterating a Set is worse. Sort it, or do not put it in the prefix at all.






Mistake 3: a per-user tool set



I built the tool list dynamically based on the user. Tools render at position 0, so a per-user tool set means nothing caches across users:




// WRONG: different users get different tool arrays at position 0
tools: buildToolsForUser(user),
// RIGHT: a stable, deterministic tool list, sorted by name
tools: ALL_TOOLS, // gate behavior with tool_choice or message content instead









Adding the breakpoint



Once the prefix was actually stable, I added one cache_control marker on the last system block. That caches tools plus system together:




const response = await client.messages.create({
model: "claude-opus-4-8",
max_tokens: 16000,
system: [
{
type: "text",
text: LARGE_STABLE_SYSTEM_PROMPT,
cache_control: { type: "ephemeral" },
},
],
messages: [{ role: "user", content: userQuestion }],
});









The economics



Cache reads cost about 0.1x base input price. Cache writes cost 1.25x for the 5-minute TTL. So you break even on the second request and win on every one after. For my auditor, where the system prompt and the contract-analysis instructions are identical across every call in a session, the savings were dramatic: the uncached portion shrank to just the contract source and the question.



My bill on the input side dropped roughly 80%, because the part that was constant (the bulk of the tokens) was finally being served from cache instead of paid for fresh every time.






The audit checklist



If cache_read_input_tokens is stuck at zero, grep your prompt-building code for:





  • Date.now(), new Date(), time.time() anywhere in the prefix


  • crypto.randomUUID() or request IDs early in the content


  • JSON.stringify without sorted keys, or iterating a Set

  • user or session IDs interpolated into the system prompt

  • tool lists that vary per request or per user



Fix those, add one breakpoint on the last stable block, and watch the read tokens climb. The bytes have to be identical. That is the whole game.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Prompt Caching Cut My Claude Bill by 80%: The Mistakes That Were Costing Me

Thematisch verwandte Begriffe: Prompt, Caching, Claude, Bill · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-82412 | ntopng is a web-based network traffic monitoring application. Prior to 6…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick