ai newsDi., 1. Dez.

Prompt caching: the 50% discount most teams never claim

Most teams pay full price for the same prompt thousands of times a day. Prompt caching exists precisely for that, and it is usually the largest single discount available — bigger than switching providers, and it requires no model change. Here is how it actually behaves, and why it often silently do

dev.toSamstag 16:48 · 28.11.2 Min. Lesezeit
Bild: dev.to

Most teams pay full price for the same prompt thousands of times a day. Prompt caching exists precisely for that, and it is usually the largest single discount available — bigger than switching providers, and it requires no model change.

Here is how it actually behaves, and why it often silently does nothing.

Only the prefix of your request. Providers hash the beginning of the prompt, and if an identical prefix was seen recently, the computation is reused and billed at a discount (typically 10–50% of the normal input rate, provider-dependent).

Rule: everything variable goes last. The first byte of your prompt should be the part that is byte-identical across calls.

Almost every OpenAI-compatible API returns usage detail:

"usage": { "prompt_tokens": 4210, "completion_tokens": 180, "prompt_tokens_details": { "cached_tokens": 3900 } } Enter fullscreen mode Exit fullscreen mode If cached_tokens is 0 (or the field is missing), you are paying full price. Run the same request twice back-to-back and compare: the second call should show a materially lower effective input rate.

If it stays zero, the usual causes are, in order:

A support assistant sending 4,000 input tokens per call, 5,000 calls/day:

At a $2.50/M input price that is roughly $37/day → $27/day. Nothing about the application changed except the order of the string.

Cache invalidation is silent. Editing the system prompt, changing a model version, or even switching providers invalidates everything. After a prompt change, watch cached_tokens for a day — a permanent zero means your "optimisation" quietly cost you 25%.

Cache hits are not free money on short prompts. If your prompt is 300 tokens, there is nothing to cache. Caching matters for RAG and agent workloads with fat, stable prefixes — the exact shape where people usually give up and downgrade the model instead.

If you do one thing after reading this: log prompt_tokens_details.cached_tokens for a week. You will either find a 20–40% discount sitting unclaimed, or you will learn that your prompts are shaped in a way that can never be cached — which is worth knowing before you spend weeks shopping for a cheaper per-token price.

Disclosure: I work on Tapix AI, an OpenAI-compatible API with prepaid billing from $1. Cache behaviour above is standard across OpenAI-schema providers; the price index publishes per-model prices if you want to redo the arithmetic with your own numbers, and the glossary entry on prompt caching has the short version.

Quelle: dev.to (dev.to). Original öffnen