OpenAI automatic caching
Since GPT-4o, OpenAI automatically caches prefixes ≥1024 tokens, with no client configuration needed.- The cache-hit price is typically 0.5× of the input price (GPT-4o) or 0.1× (o3 / GPT-5).
- The response
usage.prompt_tokens_details.cached_tokensfield shows the number of hits.
Claude cache_control
Claude marks cache segments explicitly with cache_control:
- Write: creating the cache the first time costs 1.25× the input price (25% more).
- Hit: the same prefix within the next 5 minutes costs 0.1× the input price.
- TTL: 5 minutes (extendable via
ttl: "1h"in cache_control, if the corresponding product supports it).
DeepSeek automatic caching
DeepSeek-V3 / R1 automatically cache long prefixes; cache hits are billed at the very low unit price the vendor publishes (typically about 0.1× of the original).- The number of hits is shown in the
usage.prompt_cache_hit_tokensfield. - OpenPAI passes it through and bills accordingly.
Google Gemini Context Caching
The Gemini 2.5 series supports the explicitcachedContents API:
cached_content reference, and the hit portion is settled at Google’s published cache price.
Console display
In the call log you can see:| Field | Meaning |
|---|---|
| Input tokens | The raw input sent by the client |
| Cache-hit tokens | The portion that hit the cache |
| Cache multiplier | The multiplier billed for the hit portion |
| Cache-write tokens | Claude only, the extra higher-priced first-write portion |
Best practices
Put invariant content first
System prompts, RAG results, few-shot examples → place them at the front of the messages array, then append the user’s question.
Share a prefix across batched requests
Ask different questions under the same long context to maximize cache-hit benefit.
Control variability
Avoid inserting timestamps or random numbers into the prefix, or the prefix won’t match and won’t hit.
Measure the benefit
Watch the
cached_tokens ratio in the logs to optimize your prompt structure.Caveats
- The cache-hit rate depends on actual upstream availability; OpenPAI does not fabricate cache hits.
- Cross-channel-routed requests may switch between two upstream accounts, invalidating the cache — for cache-dependent scenarios, bind a fixed channel to the model in the console.
- Cached content is stored encrypted by the upstream vendor; OpenPAI does not store any prompt content.