Summary
During an agent session on May 23, 2026, using deepseek/deepseek-v4-pro on the Command Code platform, prompt caching was observed to be working inconsistently. While most calls correctly utilized the cache and cost between $0.0001–$0.0008, every 10–15 calls the cache unexpectedly invalidated and charged full price at $0.037–$0.040 — roughly 80–200x more expensive than a normal cached call.
The session ran for approximately 1.5 hours with context growing from ~54K to ~155K tokens across 100+ consecutive agent calls. The total session cost was estimated to be 2–3x higher than expected due to these recurring cache misses.
The root cause is likely the agent harness injecting dynamic content before the cache boundary, missing explicit cache_control markers, or tool outputs disrupting the cache prefix hash — causing DeepSeek's prompt cache to reset mid-session instead of persisting for the full session duration. Proper caching should populate once on the first call and remain stable throughout, billing only for new tokens on every subsequent call.
Expected Behavior
Prompt cache should be populated on the first API call and maintained throughout the session. All subsequent calls with the same context prefix should hit the cache, billing only for new tokens at the discounted rate (~$0.0001–$0.0003 per call).
Actual Behavior
Every 10–15 calls, the cache unexpectedly resets and charges full price ($0.037–$0.040), which is 80–200x more expensive than a normal cached call. This recurs randomly throughout the session — not just on the first call — inflating total session cost by 2–3x.
Steps to reproduce the issue
Start an agent session using deepseek/deepseek-v4-pro model
Run a long agentic task with 50+ consecutive API calls
Allow context to grow incrementally (100K–155K tokens)
Observe the usage dashboard for cost spikes
Note recurring full-price calls (~$0.038) appearing every 10–15 calls despite unchanged system prompt context
Command Code Version
0.26.23
Operating System
macOS
Terminal/IDE
tmux
Shell
bash
Additional context
No response
Summary
During an agent session on May 23, 2026, using
deepseek/deepseek-v4-proon the Command Code platform, prompt caching was observed to be working inconsistently. While most calls correctly utilized the cache and cost between $0.0001–$0.0008, every 10–15 calls the cache unexpectedly invalidated and charged full price at $0.037–$0.040 — roughly 80–200x more expensive than a normal cached call.The session ran for approximately 1.5 hours with context growing from ~54K to ~155K tokens across 100+ consecutive agent calls. The total session cost was estimated to be 2–3x higher than expected due to these recurring cache misses.
The root cause is likely the agent harness injecting dynamic content before the cache boundary, missing explicit
cache_controlmarkers, or tool outputs disrupting the cache prefix hash — causing DeepSeek's prompt cache to reset mid-session instead of persisting for the full session duration. Proper caching should populate once on the first call and remain stable throughout, billing only for new tokens on every subsequent call.Expected Behavior
Prompt cache should be populated on the first API call and maintained throughout the session. All subsequent calls with the same context prefix should hit the cache, billing only for new tokens at the discounted rate (~$0.0001–$0.0003 per call).
Actual Behavior
Every 10–15 calls, the cache unexpectedly resets and charges full price ($0.037–$0.040), which is 80–200x more expensive than a normal cached call. This recurs randomly throughout the session — not just on the first call — inflating total session cost by 2–3x.
Steps to reproduce the issue
Start an agent session using deepseek/deepseek-v4-pro model
Run a long agentic task with 50+ consecutive API calls
Allow context to grow incrementally (100K–155K tokens)
Observe the usage dashboard for cost spikes
Note recurring full-price calls (~$0.038) appearing every 10–15 calls despite unchanged system prompt context
Command Code Version
0.26.23
Operating System
macOS
Terminal/IDE
tmux
Shell
bash
Additional context
No response