Immutable solution version
Roll out OpenAI prompt caching: stable prefixes, verify cached_tokens, measure savings
Complete solution
Prompt caching discounts reused input tokens up to 90%, but only when the prompt is engineered for it: a stable prefix of at least 1,024 tokens, identical across requests. Roll it out deliberately and verify the hits.
Prompt caching rollout
The steps
- Measure the baseline first: log
usage.prompt_tokens_detailson a sample of requests and note what is billable today. You cannot prove savings without a before number. - Restructure prompts so the stable content comes first: system instructions, tool definitions, few-shot examples, then the variable user content last. Caching works on prefixes, so anything that changes per request must sit at the end.
- Check the minimum: the cacheable prefix must reach at least 1,024 tokens for current models. Short prompts do not qualify; do not expect caching on a 200-token system message.
- Keep the prefix byte-identical across requests. One dynamic timestamp or user id injected early in the prompt breaks the cache for everything after it. Move volatile fields to the end or out of the prompt entirely.
- Verify with
cached_tokensin the usage object. If cached tokens stay at zero, the prefix is not stable or is under the minimum; fix the structure, not the API call. - For workloads that need separate cache accounting or routing control, use a stable
prompt_cache_key. This keeps distinct workflows from evicting each other's cached prefixes.
The trap
Assuming caching is automatic. The API caches opportunistically on matching prefixes; a prompt that shuffles content order per request gets zero hits and the team concludes caching "does not work."
Checklist
- Baseline token usage logged before the rollout.
- Stable prefix of 1,024+ tokens, volatile content last.
- cached_tokens verified nonzero in production traffic.
- promptcachekey set where workflows share a model.
- Savings re-measured monthly; prompt edits re-verified for cache hits.
Evidence
OpenAI's prompt caching guide documents the 1,024-token minimum, discounts up to 90%, cachedtokens in usage, and promptcache_key. Verified live at https://developers.openai.com/api/docs/guides/prompt-caching.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_496t6VYaNk4fg4d2bMXD1A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Roll out OpenAI prompt caching: stable prefixes, verify cached_tokens, measure savings <span>— Vectle</span></a>