Prompt Cache
Prompt Caching is a powerful performance optimization feature that allows you to reuse specific prefix content in your requests. This approach can significantly reduce processing time and call costs, particularly suitable for scenarios containing large amounts of static content.Caching Types Overview
Models supported by ShuYou offer two types of prompt caching mechanisms:Type 1: Implicit Caching
The following model series provide implicit automatic prompt caching functionality, requiring no special parameters in requests—the model automatically detects and caches reusable content.Type 2: Explicit Caching
Anthropic Claude and Qwen series models can explicitly specify caching strategies through specific parameters. This approach provides the finest control but requires you to actively manage caching strategies.Caching Working Principle
When you send a request withcache_control markers:
- The system checks if a reusable cache prefix exists
- If a matching cache is found, cached content is used (reducing cost)
- If no match is found, the complete prompt is processed and a new cache entry is created
tools → system → messages (in this order), up to where cache_control is marked.
You only need to add a cache breakpoint at the end of static content, and the system will automatically check approximately the preceding 20 content blocks for reusable cache boundaries. If the prompt contains more than 20 content blocks, consider adding additional
cache_control breakpoints to ensure all content can be cached.Caching Limitations
Minimum Cache Length
Minimum cacheable token count for different models:Cache Validity Period
- Default TTL: 5 minutes
- Extended TTL: 1 hour (requires additional fee)
Cache Breakpoint Count
Each request can define a maximum of 4 cache breakpoints.Usage Methods
Basic Usage: Caching System Prompts
OpenAI Python SDK
Anthropic Python SDK
Advanced Usage: Caching Tool Definitions
When your application uses many tools, caching tool definitions can significantly reduce costs:OpenAI PythonSDK
Anthropic Python SDK
By adding a
cache_control marker on the last tool definition, the system will automatically cache all tool definitions as a complete prefix.Advanced Usage: Caching Conversation History
In long conversation scenarios, you can cache the entire conversation history:OpenAI Python SDK
Anthropic Python SDK
Advanced Usage: Multi-Breakpoint Combination
When you have multiple content segments with different update frequencies, you can use multiple cache breakpoints:OpenAI Python SDK
Anthropic Python SDK
Using multiple cache breakpoints allows content with different update frequencies to be cached independently:
- Breakpoint 1: Tool definitions (almost never change)
- Breakpoint 2: System instructions (rarely change)
- Breakpoint 3: RAG documents (may update daily)
- Breakpoint 4: Conversation history (changes every round)
What Invalidates Cache
The following operations will invalidate part or all of the cache:Best Practices
Maximizing Cache Hit Rate
Extending Cache Time (1-hour TTL)
If your request intervals may exceed 5 minutes, consider using 1-hour cache:Avoiding Common Pitfalls
FAQ
Do Implicit Caching Models Require Configuration?
No. Implicit caching models like OpenAI, DeepSeek, Grok, Gemini, Qwen automatically manage caching without requiring any special parameters in requests.These two model series support both implicit and explicit modes. Implicit mode triggers automatically, while explicit mode requires proactive control through API parameters (such as
cache_control).How to View Cache Data?
You can view the Prompt Token details of requests in the ShuYou Logs interface, as shown below:

