Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

cacheplan

Find out whether prompt caching will save you money, before you switch it on.
Diagnose your prompts, forecast every caching option, get a plan, and verify it live.

PyPI CI Python 3.10+ No dependencies Apache-2.0

Input cost with caching relative to no caching: LangGraph ReAct template 125% automatic, 51% with cacheplan; Aider 125% automatic, 66% with cacheplan; Claude Code 27% either way

Prompt caching can cut your input bill by more than half. It can also raise it by 25%, because every cache write costs extra and is wasted if nothing reads it back. Which one you get depends on how your application assembles its prompts and how quickly requests arrive, and neither shows up as an error.

cacheplan reads a log of your requests and answers three questions for each application:

Question What you get
What is breaking my cache? The exact place the reusable prefix breaks, what changed there, and how many tokens you re-pay for
What would each option cost? A forecast for caching off, automatic caching and planned breakpoints, each with the 5-minute and 1-hour lifetime
What should I do? One recommendation with instructions, and a live check that compares the forecast with the real API

It runs on your machine, has no dependencies, and needs no API key except for the optional live check. Status: early alpha, Anthropic Messages API only.

Contents

Quick start

1. Install

pip install --pre cacheplan

2. Get a log of your requests. If you don't have one, record it. Start the proxy:

cacheplan capture --out requests.jsonl --app my-app

Then point your application at it and use it as normal for a few minutes:

# macOS / Linux
export ANTHROPIC_BASE_URL=http://127.0.0.1:8787
# Windows PowerShell
$env:ANTHROPIC_BASE_URL = "http://127.0.0.1:8787"

The proxy writes request bodies only. Headers never reach the file, so your API key stays out of it.

3. Get the verdict

cacheplan report requests.jsonl

4. Optional: confirm it against the real API (one output token per request)

cacheplan verify requests.jsonl --model <your-model> --yes

How it works

Your application sends requests; they are recorded in a request log; cacheplan report diagnoses, forecasts and recommends; cacheplan verify optionally replays live

  1. Diagnose. Each request is compared with earlier ones from the same application to find where the shared prefix ends and why.
  2. Forecast. A local model of the provider's caching rules (breakpoints, the 20-block lookback, lifetimes, minimum length, write and read prices) replays your log under every option, using the real timing between your requests.
  3. Recommend. It picks the cheapest option, prefers the simpler one when two are within two points, and tells you to keep your current settings when they are already good.
  4. Verify. Optionally, it replays the log against the live API and prints the forecast beside the measured result.

Why layout matters

A cache can only reuse the part of a prompt that comes before the first change. Where that first change falls decides everything.

Three prompt layouts: append-only conversations are almost fully reusable; content inserted mid-prompt loses everything after the insertion; a changing value at the top loses everything

Layout What happens with automatic caching What cacheplan suggests
Append-only conversation Works well Nothing, or the 1-hour lifetime if your users pause a lot
Content inserted mid-prompt Reads nothing and costs 25% more Breakpoints just before the insertion point, learned from your log
Changing value at the top (timestamp, request id, shuffled tools) Reads nothing and costs 25% more Leave caching off, or move the value; the report shows what that would unlock

Reading the report

Real output for the LangGraph ReAct agent template, abridged:

react-template
  17 requests, ~120,145 input tokens (estimate)
  Layout     changing content at the top of the prompt
  Reusable   2% of input tokens repeat an earlier prefix as written
  Pace       median 7 s between requests; 0% of pauses over 5 minutes

  Option                                Read  Cost vs no caching
  Caching off                             0%                100%  <- recommended
  Automatic caching, 5-minute             0%                125%
  Automatic caching, 1-hour               0%                199%
  Planned breakpoints, 5-minute           0%                100%
  Planned breakpoints, 1-hour             0%                100%
  Prompt fix + breakpoints, 5-minute     64%                 52%
  Prompt fix + breakpoints, 1-hour       64%                 79%

  Recommendation: leave caching off as the prompts stand.
  With the prompt fix in the findings: 52%. It changes what the model reads,
  so compare answer quality before adopting it.

  Findings
    CP001 system value <<system_time>> changes between requests; everything after it,
          including the conversation history, cannot be reused
        fix: move it to the latest user message, or make it change rarely
Line Meaning
Layout Which of the three patterns above your application follows
Reusable The ceiling: the share of input tokens that repeat an earlier prefix as your prompts stand
Pace How fast requests arrive. Long pauses let 5-minute cache entries expire
Read Share of input tokens the option would read from cache
Cost vs no caching Forecast input cost, where 100% is the same prompts with caching off. Cache writes count 1.25x (5-minute) or 2x (1-hour); reads count 0.1x on most models and less on some, looked up from the model in your log
This log The same forecast in money, when the model's price is known or --price is given
Planned breakpoints cache_control markers placed where your log shows prefixes actually repeat, and only where a write is read back often enough to pay for itself
Prompt fix What you would get after moving the changing values the findings point to. Shown separately because it changes the prompt

Commands

Command Use it to
cacheplan report LOG Get the diagnosis, forecast and recommendation. Add --json for machines, --no-content to keep prompt text out of the output
cacheplan diagnose LOG -v List every prefix break: where, what changed, tokens behind it
cacheplan verify LOG --model M --yes Replay against the live API and compare forecast with measured
cacheplan gaps LOG See how the forecast changes as pauses between requests grow
cacheplan check LOG --min-reusable 0.5 Fail a pipeline when too little of the prompt is reusable
cacheplan quality LOG --model M --yes Check whether the prompt fix changes the model's answers, against a control
cacheplan baseline LOG --save FILE / --compare FILE Save a content-free summary and fail later runs that are worse
cacheplan capture --out LOG Record requests and their token usage through a local proxy
cacheplan rules List rule ids

Useful options:

  • --learn-from OTHER.jsonl learns the breakpoint plan from one log and scores another, so the forecast is out of sample.
  • --model ID or --min-tokens N sets the minimum cacheable prompt length when the log does not name the model. Otherwise it is looked up per request.
  • --fail-on CP001,CP002 makes report exit with status 1 when those findings appear.
  • --price N sets the input price in USD per million tokens; by default it is looked up from the model.
  • --html report.html also writes a self-contained page you can forward.

Log formats. One JSON object per line, and formats can be mixed in one file: a cacheplan capture line, a raw Anthropic request body, or a promptcachelint trace record.

Real token counts

Token counts are estimated from characters unless the log holds the provider's own numbers. cacheplan capture and the in-process recorder both store the usage block of every response (never the response text). When a log has it, report:

  • calibrates its token estimate on your own traffic, including the tokens the API adds for tool use;
  • prints a forecast check: what it predicted for the settings you ran with, next to what the provider actually billed. No extra API calls are needed.

Record from inside your application

No proxy needed: wrap the HTTP transport of the Anthropic SDK client.

import anthropic
from cacheplan.record import RecordingTransport

client = anthropic.Anthropic(http_client=anthropic.DefaultHttpxClient(
    transport=RecordingTransport("requests.jsonl", app="my-app")))

Use AsyncRecordingTransport with anthropic.DefaultAsyncHttpxClient for the async client. Headers and response text are never written.

Rules

Rule Finding Typical fix
CP001 A value in the system prompt or tools changes between requests Move it to the latest user message, or make it change rarely
CP002 Tool definitions are sent in a different order Build the tool list in a fixed order
CP003 Caching is not switched on Follow the recommendation
CP004 Prompts are shorter than the minimum cacheable length Nothing to do
CP005 A per-tenant or per-user value sits before static content Move it behind the static instructions
CP006 New content is inserted before content that was already sent Use the planned breakpoints, or append new turns at the end
CP007 Previously sent message content changes between requests Keep earlier messages identical; send changing material late
CP008 Many pauses are longer than the 5-minute cache lifetime Compare the 1-hour rows
CP009 Cache writes are rarely read back with the current settings Follow the recommendation

Use it in CI

Record a short session in your test suite, then guard against changes that break the cache. As a GitHub Action:

- uses: actions/setup-python@v7
  with:
    python-version: "3.12"
- uses: shamiksaharcciit-oss/cacheplan@main
  with:
    log: captures/session.jsonl
    min-reusable: "0.5"
    fail-on: CP001,CP002
    baseline: captures/baseline.json   # optional, from `cacheplan baseline --save`

The report is added to the job summary without prompt text. Or call the commands directly:

- run: pip install --pre cacheplan
- run: cacheplan check captures/session.jsonl --min-reusable 0.5
- run: cacheplan baseline captures/session.jsonl --compare captures/baseline.json

One developer adding a timestamp to the system prompt can silently undo a cache saving. This catches it in the pull request.

Benchmark: six agent starters

The same three conversations through each framework's default agent, measured on the live Anthropic API on 23 November 2026. Input cost is relative to the same requests without caching. Scripts and method: benchmarks/frameworks.

Framework Version As shipped Automatic caching Best option measured Finding
smolagents ToolCallingAgent 1.26.0 100% (caching off) 40% 36% planned breakpoints Caching off
Anthropic SDK tool loop 2.13.0 100% (caching off) 46% 46% automatic Caching off
LangChain create_agent 1.5.2 100% (caching off) 46% 46% automatic Caching off
Pydantic AI Agent 2.71.0 100% (caching off) 48% 48% automatic Caching off
CrewAI Agent 1.15.44 90% (caches by default) 99% 90% as shipped Short prompts
LangGraph ReAct template langgraph 1.2.24 100% (caching off) 124% 51% after moving the timestamp Timestamp in the system prompt (issue)

Five of the six ship with caching off. For four of them, switching it on roughly halves the input bill. For one it raises the bill, and cacheplan says why.

A correction to these figures. They were computed with cache reads priced at 0.1x an input token. Anthropic's price list gives 0.05x for the model used here, so the true cost of every row that reads from the cache is lower than shown, by 0.05 times its read share: about 3 points for the LangGraph fix (64% read) and 2 points for Aider's breakpoints. Rows that read nothing, such as the 124% and 125%, are unaffected. From 0.2.0a1 the read price is looked up per model.

How accurate is the forecast?

Forecasts checked with cacheplan verify against the live API (one model, short sessions):

Application Option Forecast Measured
LangGraph ReAct template Automatic caching, 5-minute 125% 124%
LangGraph ReAct template Prompt fix + breakpoints, 5-minute 53% 51%
Anthropic SDK tool loop Automatic caching, 5-minute 45% 46%
LangChain create_agent Automatic caching, 5-minute 45% 46%
Pydantic AI Agent Automatic caching, 5-minute 48% 48%
smolagents ToolCallingAgent Planned breakpoints, 5-minute 37% 36%
Aider Planned breakpoints, 5-minute 63% 62%
Aider Planned breakpoints, 1-hour 91% 90%
Aider Aider's own caching (--cache-prompts) 65% 64%
CrewAI Agent CrewAI's own caching 100% 90%
CrewAI Agent Automatic caching, 5-minute 111% 99%

Nine of the eleven are within two points. The CrewAI rows are the miss, made by version 0.1.0a1: its prompts are short, and the forecast wrongly predicted they were below the minimum cacheable length. Token counts are estimated from characters, so prompts near the minimum remain the least reliable case, and the report now warns when that applies.

For Aider, the breakpoint plan was learned from one session and scored on a different one, and it matched Aider's hand-tuned caching. Claude Code was at its ceiling already (27%, local model only), and cacheplan correctly recommended changing nothing.

Limits

  • Small evidence base. Eight applications, one or two short sessions each, one model.
  • The forecast is a model. It follows the documented caching rules. Tokens are estimated from characters unless the log has recorded usage, in which case the estimate is calibrated on it. Run verify before acting on a close call.
  • Minimum cacheable length varies by model. It is looked up from the model in your log; set --model or --min-tokens if the log does not name one. Forecasts for prompts close to the minimum are rough.
  • The prompt fix changes what the model reads. It never drops content. cacheplan quality compares answers with and without it against a control, on actions taken and wording; that is a screen, not a full evaluation, and it has only been tested against a stand-in so far.
  • Plans are chosen by replaying the log you give it, with its real timing, separately for each cache lifetime. A short or unrepresentative log gives a poor plan. Use --learn-from to test on a second log.
  • Prices and minimums are a snapshot of Anthropic's documentation on 23 November 2026.
  • Savings apply to input tokens only. Output tokens are unaffected.
  • Anthropic only in this release.

promptcachelint and cachelint explain why a prompt cache missed, and both support OpenAI as well as Anthropic. If you only need miss diagnosis, or you use OpenAI, look at them first.

promptcachelint cachelint cacheplan
Find where the prefix breaks Yes Yes Yes
Flag timestamps and similar Yes Yes Yes
OpenAI support Yes Yes Not yet
In-process SDK recording Yes Yes Yes
Forecast cost for each caching option Yes
Plan where to place breakpoints Yes
Recommend off, 5-minute or 1-hour Yes
Verify against the live API Yes

Comparison made on 23 November 2026 against promptcachelint 0.1.0 and cachelint 0.3.0a1.

Roadmap

  • Read Langfuse, LangSmith, OpenTelemetry and LiteLLM exports
  • OpenAI, then other providers
  • A wrapper that applies the plan automatically, once the quality check has more evidence
  • Longer sessions and more frameworks in the benchmark

Development

git clone https://github.com/shamiksaharcciit-oss/cacheplan
cd cacheplan
pip install -e ".[dev]"
python -m pytest -q

Issues and pull requests are welcome, especially logs (with content removed) from applications where the forecast and the live result disagree.

Licence: Apache-2.0.

Metadata

Release files for cacheplan 0.2.0a1

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

Source distribution (sdist)

Source distribution for cacheplan 0.2.0a1
File Size Uploaded Provenance Actions
cacheplan-0.2.0a1.tar.gz 64.9 kB With provenance Details for cacheplan-0.2.0a1.tar.gz

Built distribution (wheel)

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

Total release size: 113.7 kB

Release files / cacheplan-0.2.0a1.tar.gz

Download URL cacheplan-0.2.0a1.tar.gz
Size 64.9 kB
Tags Source
SHA-256 checksum
How to use checksums
45640275f4627c377912bb211b961d31a689d985e0a1d67360ec8bcf1dc6d352
BLAKE2b-256 checksum
How to use checksums
1f4ad2fef6adef159075d43c85414c439cd27dcc70c5c9388dbedd6c8afef630
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 Nov 23, 2026.

Transparency log

Release files / cacheplan-0.2.0a1-py3-none-any.whl

Download URL cacheplan-0.2.0a1-py3-none-any.whl
Size 48.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b51cd4fd2dec8284e7901f7f6dcb4d24390be1376d0c61a012dfb978dbc051d5
BLAKE2b-256 checksum
How to use checksums
6ddbc6c3972d236d488211e6815c2c4d3346e5881817c4c2609fb1ab178cb66b
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 Nov 23, 2026.

Transparency log

Security for cacheplan 0.2.0a1

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 cacheplan-0.2.0a1.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 Nov 23, 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