Skip to main content

cachellm

Auto-optimize LLM prompt caching. One line of code, 60-90% savings on your API bill.

Install

pip install cachellm

Quick Start

Anthropic (Claude) — saves up to 90%

from anthropic import Anthropic
from cachellm import optimize_anthropic

client = optimize_anthropic(Anthropic())

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    system="You are a helpful cooking assistant...",
    messages=[{"role": "user", "content": "How do I make biryani?"}],
)

client.print_stats()

OpenAI (GPT) — saves up to 50%

from openai import OpenAI
from cachellm import optimize_openai

client = optimize_openai(OpenAI())

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant..."},
        {"role": "user", "content": "Hello"},
    ],
)

client.print_stats()

Configuration

from cachellm import optimize_anthropic
from cachellm.types import AnthropicCacheOptions

client = optimize_anthropic(Anthropic(), AnthropicCacheOptions(
    strategy="auto",
    max_breakpoints=4,
    ttl="5m",
    min_tokens=1024,
    debug=False,
))

Standalone Analysis

from cachellm import PromptAnalyzer

analyzer = PromptAnalyzer()
analysis = analyzer.analyze_anthropic_params({
    "system": "Your long system prompt here...",
    "tools": [{"name": "search", "description": "Search the web", "input_schema": {"type": "object"}}],
    "messages": [{"role": "user", "content": "Hello"}],
})

print(f"Cacheable: {analysis.cacheable_tokens} tokens")
print(f"Estimated savings: ~{analysis.estimated_savings_percent}%")

Requirements

  • Python >= 3.9
  • Zero dependencies (provider SDKs are optional)

License

MIT

Release files for cachellm-py 0.2.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 cachellm-py 0.2.0
File Size Uploaded
cachellm_py-0.2.0.tar.gz 14.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cachellm-py 0.2.0
File Interpreter ABI Platform
cachellm_py-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.5 kB

Release files / cachellm_py-0.2.0.tar.gz

Download URL cachellm_py-0.2.0.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
564f457da0fb6d099aab7b08f6cfbcd9b1a8d88680a566e6455e510278f6b879
BLAKE2b-256 checksum
How to use checksums
d854b38c1e59ec0f8b12e0886cdb4b4c6907147d920ccec83515a26fd43ab46d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 24, 2026.

Transparency log

Release files / cachellm_py-0.2.0-py3-none-any.whl

Download URL cachellm_py-0.2.0-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0754d60caea24a9d5a8d3138638b4ff39fa1734513e3484282e9d248dc9bc27a
BLAKE2b-256 checksum
How to use checksums
c611f92b166c121a7bbf6c2fbc3efdde4c661a6d8b2ab29e9ccbbce28f2e10ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

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