DeepSeek Rust CLI includes built-in optimizations to take advantage of DeepSeek's context caching (KV cache) and minimize token usage, keeping your API costs low.
DeepSeek API automatically caches the context on the server side using Context Caching on Disk. Since cache hits are significantly cheaper (approximately 10x-12x cheaper) than cache misses, maximizing cache hits is the most effective way to reduce costs.
For a subsequent request to hit the cache:
- The input prefix must fully match a previously persisted cache prefix unit.
- A cache prefix is persisted at:
- Request boundaries: The end of the user input and the end of the model output.
- Common prefix detection: When the system detects a common prefix across multiple requests.
- Fixed token intervals: To support caching portions of long inputs.
To maximize KV Cache hits and reduce raw token usage, the CLI implements the following strategies:
The list of tools and the base system prompt are serialized and sent in the exact same order and format in every request. Because they form the initial prefix of every API request in a session, subsequent turns will achieve a 100% cache hit on the system instructions and tool definitions.
You can configure limits on context length to prevent ballooning costs while maintaining stable caching:
max_context_chars(default:100000): The maximum characters of conversation history kept. Once exceeded, older messages are pruned to prevent context overflow.max_tool_output_chars(default:15000): Limits the size of tool outputs stored in the chat history. Large compiler logs or file reads are truncated, saving valuable prompt tokens in subsequent turns.
You can monitor your cache hits and token savings in real time:
- TUI Footer: The second line of the TUI footer displays real-time token statistics in the format:
📊 <total_prompt> prompt (<hit_count> hit) · <comp> comp · <total> total - Slash Commands:
- Run
/tokensto see a detailed breakdown of prompt tokens (hits vs. misses) and completion tokens. - Run
/infoto view overall session metadata and token counts.
- Run
- Execution Summary: If
show_token_usageis enabled in your configuration, the CLI outputs a colored summary at the end of each task loop showing exactly how many prompt tokens were cache hits.