Skip to content

callm

The production toolkit for LLM calls. Caching, retries, provider fallback, cost tracking, budgets, PII redaction, prompt-injection detection, structured output validation and telemetry — in one decorator, on top of the SDKs you already use.

from callm import callm

@callm(
    cache=True,                          # response cache (SQLite by default)
    retry=3,                             # exponential backoff on 429/5xx
    fallback=["anthropic/claude-sonnet-5"],  # auto-switch on failure
    max_cost=0.25,                       # hard budget per call
    block_pii=True,                      # mask emails, phones, SSNs, cards
    detect_injection=True,               # flag prompt injection attempts
    output_schema=MyResponse,            # Pydantic validation + auto-retry
)
def summarize(text: str) -> MyResponse:
    return openai.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": text}],
    )

What makes callm different

  • Keep your code. callm intercepts the official openai, anthropic and google-genai SDK calls inside decorated functions and returns the SDK's own response objects.
  • No infrastructure. No proxy to deploy, no database server, no SaaS account. State lives in a local SQLite file, in memory, or in Redis when you want a shared cache.
  • Zero required dependencies. The core is pure standard library. Optional extras add SDKs, Pydantic, embeddings, spaCy, Redis and OpenTelemetry.
  • Sync and async. Identical behaviour for def and async def, including under asyncio.gather.

Features

Feature Summary Guide
Retries Backoff with jitter; honours every provider's rate-limit headers Retries
Caching Exact-match by default, semantic on request; SQLite, memory or Redis Caching
Fallback Ordered provider chains with request translation Fallback
Cost Per-call cost, max_cost, shared budgets per function, session or user Cost
Security PII masking and prompt-injection scoring before requests leave your process Security
Validation Pydantic output schemas with automatic repair Structured output
Telemetry Local call records, CLI dashboard, hooks, OpenTelemetry Telemetry

Install

pip install "callm-toolkit[openai]"   # plus the providers you use
pip install "callm-toolkit[all]"      # everything

Continue with the quickstart.