prompt-cache-warmer
Pre-warm Anthropic prompt cache before user traffic hits.
Anthropic charges 25% more on the first request that creates a cache entry and only 10% on subsequent reads. If you have a long system prompt or a tool list, you want the first cache write to be a cheap synthetic warmup at deploy time, not a real user paying for it (and waiting for it).
use ;
// Plug in any transport that implements `WarmCall`.
let warmer = new;
let result = warmer
.warm_verified
.unwrap;
println!;
println!;
println!;
That's it. Warmer injects cache_control breakpoints into your system blocks, fires a tiny max_tokens = 8 call, and optionally fires a second call to assert the cache actually read back.
Install
[]
= "0.1"
Zero runtime dependencies. Bring your own HTTP client by implementing the WarmCall trait.
Why
The first request that creates a cache entry costs 1.25x the regular input price. Every subsequent request that reads it costs 0.10x. If your system prompt is 50k tokens, that first hit is the difference between a snappy response and a user waiting two seconds for the prompt to be processed from scratch.
Run Warmer from a deploy hook or a cron and the first user request hits a warm cache.
API
// Construct
let warmer = new; // default price table
let warmer = with_prices; // BYO pricing
// Shortcuts
let result = warmer.warm?;
let result = warmer.warm_verified?;
// Full input
let mut input = new;
input.tools = my_tools;
input.breakpoints = 2;
let result = warmer.warm_with?;
Warmer<C> is generic over a WarmCall trait:
Implement it once for whichever HTTP client you use (the official Anthropic SDK wrapper, a Bedrock crate, reqwest, or a fake).
Companion libraries
prompt-cache-warmer warms the cache. cachebench measures the resulting hit ratio over time. Run the warmer once at deploy, then have cachebench keep score.
For runtime cost tracking, pair with claude-cost (Rust) or wire the same multipliers into your own logging.
A Python port lives at prompt-cache-warmer on PyPI.
License
MIT OR Apache-2.0