driftcast
Cost and trace telemetry for agent frameworks. Captures actual tokens, cost, latency, and errors as your agent runs, persisted to a local SQLite file.
You own your data. DriftCast is content-agnostic by default: it records the shape and economics of execution (token counts, cost, latency, status, structure) — never your prompts, completions, or documents. Everything is written to a local file you control; there is no DriftCast server in the data path. Unlike cloud-coupled tracers (which go dark under Zero Data Retention policies), there is nothing to switch off. See Data ownership.
One decorator, one explicit call. @lens.track turns any function into a
tracked run or span automatically — nesting into a call-tree on its own. The
only thing you pass by hand is token usage (driftcast.record(...)), because
provider response shapes differ across providers and call types (embeddings vs.
chat completions). Everything else — cost lookup, latency, structure,
persistence — is automatic.
Install
pip install driftcast
Optional local dashboard (Gradio):
pip install "driftcast[dashboard]"
The core SDK is stdlib-only. driftcast[dashboard] adds the local Gradio
viewer (driftcast dashboard). Claude Code capture via the OTLP receiver
(driftcast-otel) is included in the core install.
Build from source:
git clone https://github.com/AkashRK1216/driftcast
cd driftcast
pip install -e ".[dashboard]"
Usage
Decorate your functions with @lens.track. The outermost decorated call
becomes a run (one full pipeline execution); nested decorated calls become
spans (individual provider calls), auto-parented into a tree. Inside a span,
call driftcast.record(...) once to report token usage.
import driftcast
lens = driftcast.init(project="rag-agent", db_path="./driftcast.db")
@lens.track(model="text-embedding-3-small")
def embed_query(query):
result = openai_client.embeddings.create(model=EMBED_MODEL, input=query)
driftcast.record(input_tokens=result.usage.prompt_tokens, output_tokens=0)
return result
@lens.track(model="gpt-4o-mini")
def generate_answer(query):
response = openai_client.chat.completions.create(...)
driftcast.record(
input_tokens=response.usage.prompt_tokens,
output_tokens=response.usage.completion_tokens,
)
return response.choices[0].message.content
@lens.track # the top-level call is the run
def ask(query):
driftcast.annotate(customer_id="acme") # business labels onto the run
embed_query(query)
return generate_answer(query)
ask("what is the refund policy?")
@lens.track(model=None, name=None)— the whole API. The outermost decorated call opens a run; nested decorated calls become spans, auto-nested by call depth. On exit each recordscost,latency_ms, and status; an exception is recorded asstatus="error"and re-raised — tracing never masks a real failure. Works on sync andasyncfunctions.driftcast.record(input_tokens, output_tokens, content=None)— call once inside a@lens.track(model=...)function to report what the provider call consumed. This is the one number you pass by hand (provider usage shapes differ). Passcontent=to persist prompt/response only whencapture_content=True(see Data ownership).driftcast.annotate(**labels)— attach business labels (route,customer_id, judge verdicts…) to the current run's metadata. Always stored, never treated as content.driftcast.outcome(accepted, wasted=[...])— at the end of a run, record your own ground-truth label (what you accepted / what was wasted). Content-free; persisted into the run's metadata.
Data ownership
driftcast.init(..., capture_content=False) is the default. In that mode:
- Content passed via
content=is dropped before persistence. Token counts, cost, latency, and structure are still recorded — enough for cost attribution and tracing, with zero prompt/response data at rest. - Error messages are reduced to the exception type (e.g.
RateLimitError), since provider errors can echo input content. The full message is kept only when content capture is on. - Metadata is stored separately from content, so per-customer attribution (
customer_id=...) never requires storing a prompt.
Set capture_content=True to also persist content= payloads for debugging — written only to your local db_path, never transmitted anywhere. This is the design that lets DriftCast run under Zero Data Retention policies where cloud-coupled tracers cannot.
Cloud (opt-in)
DriftCast is local-first: by default nothing leaves your machine. To send completed runs to a DriftCast cloud endpoint — for waste attribution and percentile benchmarks across your runs — set two environment variables:
DRIFTCAST_CLOUD_KEY your cloud API key (enables shipping)
DRIFTCAST_CLOUD_URL the ingest endpoint base URL
When DRIFTCAST_CLOUD_KEY is unset, behavior is unchanged and no network or
background thread is created. Shipping is best-effort and happens after the
local write — if the endpoint is unreachable, the run is still recorded locally.
Only structural telemetry is sent by default (call tree, tokens, cost,
latency, error topology, accepted/wasted outcome) — never prompt or completion
content. Content is sent only if you also set DRIFTCAST_CLOUD_SHIP_CONTENT=1
and initialized with capture_content=True.
CLI
driftcast summary --db ./driftcast.db [--project rag-agent]
Prints an aggregate report grouped by run and by model — total cost, total tokens, run count, average latency.
Live dashboard
A web dashboard renders the same data as a live, auto-refreshing view (headline totals, runs, per-model cost/tokens/latency). Gradio is an optional extra — the core SDK stays stdlib-only.
pip install -e ".[dashboard]" # installs gradio
driftcast dashboard --db ./driftcast.db --project rag-agent --port 7861
To pop it automatically alongside an agent's own UI, launch it non-blocking:
import driftcast.dashboard as dashboard
# returns immediately; server runs in a background thread on its own port
dashboard.launch(db_path="./driftcast.db", project="rag-agent", port=7861, block=False)
The RAG test agent does exactly this — running python main.py opens the chat
UI and the stats dashboard side by side (dashboard on port 7861, override with
DRIFTCAST_DASHBOARD_PORT).
Pricing
src/driftcast/pricing.py is a plain editable $ per 1M tokens dict. Unknown
models cost $0.0 and log a warning, so untracked spend is a visible signal
to add the model rather than a silent miscalculation.
Storage
SQLite via stdlib sqlite3 — file-based, no extra dependency, matches the
"under $100, personal dogfood" scale this targets. Two tables: runs (one row
per pipeline execution) and spans (one row per provider call).
Metadata
Release files for driftcast 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| driftcast-1.1.0.tar.gz | 52.0 kB | With provenance | Details for driftcast-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| driftcast-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for driftcast-1.1.0-py3-none-any.whl |
Total release size: 89.8 kB
Release files / driftcast-1.1.0.tar.gz
| Download URL | driftcast-1.1.0.tar.gz |
|---|---|
| Size | 52.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3be04a54402c5816d2bb8a52914cdbfd3834507ce1d913dcaaea4dec9f6934cd
|
|
BLAKE2b-256 checksum How to use checksums |
39ce54d31125f16ff075c357c2d574feca72b9b46874d01ee69d8eb95b3616e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 30, 2026.
Transparency logRelease files / driftcast-1.1.0-py3-none-any.whl
| Download URL | driftcast-1.1.0-py3-none-any.whl |
|---|---|
| Size | 37.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
381d377ae3da269d623ea200ca29389b27621b3719b144e01a2fd541631d75fd
|
|
BLAKE2b-256 checksum How to use checksums |
4cdada1a3ae5d84738fa7d1bfa66a7dac9d4957fba66dc2921f29a46d64b7ba3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 30, 2026.
Transparency logSecurity for driftcast 1.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.
Attestation for driftcast-1.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 Aug 30, 2026.
Transparency logA 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.