Guide

Prompt caching: pay less for the part that does not change

Published 16 Nov 2026 · Problem, method and result · Every source is a checked official link

All guides · All case studies

Problem

A bot sends the same long instructions, tools, and reference text on every request, so the provider must process that prefix again. Input cost increases, and the wait for the first token also increases. Each new turn in a long chat usually sends the full history again.

Method

  1. Put stable content first. Start with tool definitions, system instructions, then messages. Put timestamps and new user data last.
  2. Do not change tool definitions or the start of the prompt between requests. A change at the start breaks the cache.
  3. On the Anthropic API, add cache_control. The default TTL is 5 minutes. A 1-hour TTL is available at a higher write price.
  4. On OpenAI, prompt caching is on by default for supported models when the prefix meets the minimum length. For GPT-5.6 and later, that minimum is 1,024 tokens.
  5. On the xAI API, prompt caching is automatic. Set prompt_cache_key or x-grok-conv-id. Only append new messages.
  6. Look at the cached token counts in the usage fields. Make sure that later turns show a cache hit.

Official prices from the Sources pages are as follows. On Anthropic, a cache write with a 5-minute TTL costs 1.25 times the base input price. A 1-hour cache write costs 2 times that price. A cache read costs 0.1 times the base input price on most models. Some newer models use 0.025 times or 0.05 times.

On OpenAI, cached input tokens are discounted up to 95 percent. For GPT-5.6 and later, a 30-minute cache write costs 1.25 times the uncached input rate, and a 12-hour write costs 2.5 times. Subsequent reads cost 0.1 times on most of these models, and 0.05 times on GPT-6.1 Sol and GPT-6.1 Terra. On xAI, for grok-4.7 with fewer than 200k prompt tokens, regular input is $2.00 per 1M tokens. Cached input is $0.50 per 1M tokens. For prompts of 200k tokens or more, those prices are $4.00 and $1.00 per 1M tokens.

Result

After the first cache write, later reads cost less. The first token can also arrive sooner. The benefit occurs only when the prefix matches. A change to tools, to the system prompt, or to earlier messages removes the match from that point. Prompt caching changes the price of those tokens. The tokens still count toward the context window.

Sources

  1. Anthropic, Prompt caching: https://platform.claude.com/docs/en/build-with-claude/prompt-caching
  2. OpenAI, Prompt caching: https://developers.openai.com/api/docs/guides/prompt-caching
  3. xAI, Pricing, and Prompt Caching: https://docs.x.ai/developers/pricing and https://docs.x.ai/developers/advanced-api-usage/prompt-caching

More write-ups: case studies. Related study: context rot.