$ cd ..

cachemaxxing

python
llm
prompt caching
open-source

Open-source Python library that finds why your LLM prompt cache misses and fixes it. Measures cache hits per call site, points at the exact byte where a prompt stopped repeating, and lays prompts out so they cache. 76–88% lower input cost against a sloppy app. Zero runtime dependencies.

cachemaxxing diff finding the timestamp that breaks a prompt cache, and the cached share of input before and after

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 report totals them per call site.
  • Diagnose: Stats finds the first byte where a request stopped repeating the previous one, says why, and how to fix it.
  • Fix: Prompt orders 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:

WorkloadModelNaive appcachemaxxingSaving
chatclaude-haiku-5-50% cached · $0.009094.4% cached · $0.001484%
chatclaude-sonnet-5-50% cached · $0.179192.4% cached · $0.024786%
chatgpt-6.1-sol0% cached · $0.138991% cached · $0.016888%
chatgemini-3.8-flash0% cached · $0.046897.3% cached · $0.007783%
raggemini-3.8-flash0% cached · $0.035288.2% cached · $0.008676%

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