Principle
When you send a request with prompt caching enabled, the system checks if the prompt prefix has been cached from recent queries. If found, it uses the cache, reducing processing time and costs; otherwise, it processes the full prompt and caches the prefix after the response begins. This is particularly useful in o seguinte scenarios:- Prompts containing numerous examples
- Extensive context or background information
- Repetitive tasks with consistent instructions
- Long multi-turn conversations
Core Mechanism
Different model providers have varying support for caching:Automatic Caching
Automatic caching requires no additional configuration; the system automatically identifies and caches reusable content, applicable to models like OpenAI, DeepSeek, etc.OpenAI
- Comprimento mínimo do prompt: 1024 tokens; o acerto é automático quando o prefixo é idêntico, caractere por caractere
- Modelos anteriores ao GPT-5.6: a escrita de cache não tem cobrança adicional; a leitura de cache é cobrada pelo preço de leitura de cache do modelo correspondente
- GPT-5.6 e posteriores (critério oficial “GPT-5.6 models and later model families”; atualmente gpt-5.6-sol / terra / luna): escrita de cache cobrada a 1.25x o preço de entrada e leitura a 0.1x; novos parâmetros
prompt_cache_keye pontos de quebra de cache explícitos - Uso, cobrança e solução de problemas de acerto em Cache de Prompt do GPT
Gemini
- Implicit context caching is enabled by default, and caching is automatically effective without manual configuration.
- Caching is only effective when the content, model, and parameters are identical; any differences will be treated as a new request and will not hit the cache.
- The cache validity period is set by the developer, and it can also be left unset. If unspecified, it defaults to 1 hour. There are no minimum or maximum duration limits, and costs depend on the number of cached tokens and cache duration.
DeepSeek / Grok / Moonshot / Groq
- Cost: Writing to cache is free or at the same price, reading from cache is below the original price
Cache explícito dos modelos Claude
- Ativação via
cache_control: campo de nível superior do corpo da requisição para ponto de quebra automático (move para frente com a conversa), ou em nível de bloco de conteúdo para controle preciso da posição do cache - Suportado por todos os modelos Claude ativos; escrita de cache a 1.25x na faixa de 5 minutos e 2x na de 1 hora, leitura a 0.1x, com proporções de preço uniformes em toda a linha
- Aplicável aos modelos Claude da Anthropic
O Claude define um limite mínimo por modelo (512 / 1.024 / 2.048 / 4.096 tokens), e esse valor não acompanha o número da versão: por exemplo, Opus 4.8 = 1.024, Opus 4.7 = 2.048, Opus 4.6/4.5 e Haiku 4.5 = 4.096, Fable 5 = 512. Um prefixo abaixo do limite não é escrito no cache mesmo marcado com
cache_control, e nenhum erro é retornado — na resposta, cache_creation_input_tokens e cache_read_input_tokens iguais a 0 ao mesmo tempo indicam essa situação. A tabela completa por faixa e a solução de problemas estão em Cache de Prompt do Claude.OpenAI Compatible Interface
Você pode set caching breakpoints insystem, user (including images), and tools using the cache_control field. O seguinte examples only show the key structure:
System Message Caching (default 5 minutes TTL):
cache_control at the top level of the tool object (at the same level as type and function):
Anthropic Compatible Interface
Caching Duration
- Default: 5 minutes
- Optional: 1 hour (“ttl”: “1h”)
Para mais informações, consulte: Claude Prompt Caching
Usage Recommendations
- Maintain Stable Prefixes
- Cache Large Texts
- RAG data
- Long texts
- CSV / JSON data
- Role settings
- Control TTL
- Short sessions → 5 minutes
- Long sessions → 1 hour (more cost-effective)
- Reduce Cache Writes