prompt-cache-key
Stable Anthropic prompt-cache scope hashes.
Anthropic's prompt cache hits when the prefix (system plus tools, up to a
cache_control breakpoint) is byte-identical to a previously seen request.
This crate produces a deterministic key from (model, system, tools) that
survives benign reordering of JSON keys.
Install
[]
= "0.1"
= "1"
Use
use ;
use json;
let key = compute_cache_key;
assert!;
When system contains a cache_control marker, anything after the last
marker is excluded from the key, matching Anthropic's cached prefix.
use ;
use json;
let blocks = json!;
let key = compute_cache_key;
Pairs with llm-message-hash
(hashes the full request, not just the cache scope).
License
MIT