cachemaxxing cuts the input cost of LLM calls by making prompt caching actually hit.
Why cachemaxxing
Anthropic, OpenAI and Gemini bill a repeated prompt prefix at a fraction of the input price, but only when the bytes really repeat. A timestamp at the top of the system prompt, tools sent in a different order, or JSON keys that shuffle are enough to make every call pay full price, and nothing tells you it happened.
cachemaxxing is a thin library, not a proxy: zero runtime dependencies, and you keep your own SDK client.
Measure, diagnose, fix
- Measure:
usage()turns any provider’s response into the same numbers (input, cache read, cache write, output, estimated $ and hit rate).cachemaxxing reporttotals them per call site. - Diagnose:
Statsfinds the first byte where a request stopped repeating the previous one, says why, and how to fix it. - Fix:
Promptorders a prompt from most to least stable and places each provider’s cache markers for you.
from openai import OpenAI
from cachemaxxing import Prompt, usage
p = Prompt(call_site="support.answer").messages(chat)
resp = OpenAI().chat.completions.create(**p.openai_chat("gpt-6-luna"))
# same p: anthropic.messages.create(max_tokens=1024, **p.anthropic("claude-haiku-5-5"))
u = usage(resp)
print(f"{u.hit_rate:.0%} of input from cache, ~${u.est_cost or 0:.4f}")
Finding the miss
$ cachemaxxing diff request_1.json request_2.json
diverges at system[0].text char 41 (timestamp), after ~14 matching tokens
a: 'You are helpful. Today is 2026-10-30T10:00:00Z.'
b: 'You are helpful. Today is 2026-10-30T10:05:00Z.'
cachemaxxing report calls.jsonl --min-hit-rate 0.6 exits 1 below the threshold, so a bundled GitHub Action can fail CI when a change breaks caching. --html writes the same report as a self-contained dashboard page.
Benchmark
8-turn conversations, every arm from a cold cache, estimated input cost per conversation at list price:
| Workload | Model | Naive app | cachemaxxing | Saving |
|---|---|---|---|---|
| chat | claude-haiku-5-5 | 0% cached · $0.0090 | 94.4% cached · $0.0014 | 84% |
| chat | claude-sonnet-5-5 | 0% cached · $0.1791 | 92.4% cached · $0.0247 | 86% |
| chat | gpt-6.1-sol | 0% cached · $0.1389 | 91% cached · $0.0168 | 88% |
| chat | gemini-3.8-flash | 0% cached · $0.0468 | 97.3% cached · $0.0077 | 83% |
| rag | gemini-3.8-flash | 0% cached · $0.0352 | 88.2% cached · $0.0086 | 76% |
Against a clean prompt using the provider’s own one-line caching, the gain depends on the provider: 82–89% cheaper on Anthropic, where automatic caching lands after the per-turn context and reads nothing back; 62–67% on Gemini, through an explicit cache created only when it pays; and only 6–19% on OpenAI, whose implicit caching already finds a stable prefix.
Stack & compatibility
- Providers: Anthropic, OpenAI (Responses and Chat Completions), Azure OpenAI, Gemini, LiteLLM
- Frameworks: LangChain agents (
CacheMiddleware), LangGraph and LCEL (CachedModel) - Safety: never fails a call that would have worked without it; logs can leave out prompt text
- Python: 3.11+ · Dependencies: none at runtime · License: MIT