Skip to main content

cachemaxxing

PyPI Python CI License: MIT

Stop paying full price for the same tokens.

Anthropic, OpenAI and Gemini bill a repeated prompt prefix at a fraction of the input price, but only when the bytes really repeat. cachemaxxing finds where they don't, tells you what it costs, and lays your prompts out so they do.

  • Measure. usage() normalizes every provider's usage, and cachemaxxing report gives hit rate and $ per call site.
  • Diagnose. cachemaxxing diff shows the first byte where two requests diverge, and why.
  • Fix. Prompt orders segments from most to least stable and places each provider's cache markers.
from cachemaxxing import Prompt, usage

p = Prompt(call_site="support.answer")
p.tools(TOOLS).system(SYSTEM).context(DOCS).history(messages).user(question)

resp = client.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}")

A full multi-turn RAG chat lives in examples/rag_chat.py. The API works the same with p.openai(...), p.openai_chat(...), p.gemini(...) and p.litellm(...). It is a thin library, not a proxy, and has zero runtime dependencies.

Benchmark

Cached input tokens per 8-turn chat, naive vs cachemaxxing

Provider Model Cached input $ per conversation Saving
Anthropic claude-haiku-5-5 0.0% → 94.8% $0.0092 → $0.0017 82%
OpenAI gpt-6-luna 0.0% → 93.1% $0.0070 → $0.0012 83%
Gemini gemini-3.8-flash 0.0% → 97.5% $0.0484 → $0.0094 80%

The same 8-turn conversation, 3 customers per arm, starting from a cold cache, with costs estimated at list price. The naive arm has four common habits: a timestamp at the top of the prompt, tool order that varies, JSON key order that varies, and history re-rendered every turn. The Gemini row uses an explicit cache, creation and storage cost included; with implicit caching alone it reached 40.0%. Data: benchmarks/results/, 2026-10-30.

Install

pip install cachemaxxing        # or: uv add cachemaxxing
pip install "cachemaxxing[anthropic]"   # extras: anthropic, openai, gemini, litellm

Docs: https://ashhadahsan.github.io/cachemaxxing/ covers the quickstart, how caching works per provider, diagnosing a low hit rate, the API reference, and how it compares.

MIT licensed.

Metadata

Release files for cachemaxxing 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachemaxxing 0.1.0
File Size Uploaded Provenance Actions
cachemaxxing-0.1.0.tar.gz 17.2 kB With provenance Details for cachemaxxing-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cachemaxxing 0.1.0
File Interpreter ABI Platform Actions
cachemaxxing-0.1.0-py3-none-any.whl Python 3 none any Details for cachemaxxing-0.1.0-py3-none-any.whl

Total release size: 37.5 kB

Release files / cachemaxxing-0.1.0.tar.gz

Download URL cachemaxxing-0.1.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ff8fffbfbbd5dbc98309cb8eaa65a21dcc12f5c86b3afc6aa030e6225f8f2c6d
BLAKE2b-256 checksum
How to use checksums
a3f89ada11a023fe74a5fd92ebb749b1701817250cb4b26f48d286b3f38175c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / cachemaxxing-0.1.0-py3-none-any.whl

Download URL cachemaxxing-0.1.0-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fd68cd296b41a64698ef889a7790279a2f4e0f29b0327a51a214988950ef3d8
BLAKE2b-256 checksum
How to use checksums
3fd9a257b79df4b5dafb08405fb4425f8afb1ca071d00692455b4c696d4f8c8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Security for cachemaxxing 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cachemaxxing-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page