v0.1.0 · Open Source · Apache 2.0

Know what your
AI actually costs.

Instrument once. Attribute every LLM API call to a project, feature, or workflow — with full agentic cost rollup across Anthropic, OpenAI, Gemini, and DeepSeek.

INSTALL pip install kostrack
4 providers
Anthropic · OpenAI · Gemini · DeepSeek
1 import
Zero API changes required
<5ms
Async write overhead per call
41 tests
Full coverage, 0 failures
How it works

From one import
to live dashboards.

No proxy servers. No SDK rewrites. Kostrack wraps your existing clients and writes cost data asynchronously — never blocking your LLM calls.

01
Start the stack
Run docker compose up -d. TimescaleDB and a pre-wired Grafana dashboard are ready in under a minute.
02
Configure once
Call kostrack.configure(dsn=...) at app startup with your TimescaleDB connection string. That's it.
03
Swap one import
Replace from anthropic import Anthropic with from kostrack import Anthropic. Identical API.
04
Tag and trace
Pass a tags dict to attribute costs. Wrap agentic workflows with kostrack.trace() for rollup per run.
app.py
import kostrack kostrack.configure( dsn="postgresql://kostrack:pw@localhost/kostrack", service_id="openmanagr", ) from kostrack import Anthropic client = Anthropic(tags={ "project": "openmanagr", "feature": "invoice-extraction", }) # Agentic trace — cost rolls up per run with kostrack.trace( tags={"feature": "month-end-close"} ) as t: result = agent.run(task) print(f"Cost: ${t.total_cost_usd:.6f}")
Features

Built for production
AI systems.

Everything needed for real cost governance — not just a dashboard on top of your billing page.

Async write path
Batch writer with in-memory queue. DB writes never block LLM calls. SQLite fallback if TimescaleDB is unreachable.
<5ms overhead
🔗
Agentic trace rollup
LangGraph-native. All child LLM calls in a workflow share a trace ID. Query total cost per run, not just per call.
LangGraph ready
🏷
Extensible attribution
Tag every call with project, feature, user, team, environment — any keys needed. GIN-indexed for fast queries.
Arbitrary tags
💰
Cache-aware pricing
Anthropic cache write vs read. OpenAI cached prompts. Versioned pricing — historical accuracy after provider changes.
Per-provider logic
📊
Pre-built Grafana
docker compose up gives you TimescaleDB + Grafana with pre-provisioned dashboards. Zero configuration.
Zero config
🛡
Resilient by default
Local SQLite buffer survives DB downtime and process restarts. Auto-flushes when connectivity returns.
SQLite fallback
CLI for operators
Full spend governance from the terminal. Check budgets, view traces, set limits — no Python needed. Ships with pip install kostrack.
No code required
🌐
Platform REST API
Language-agnostic governance on port 8080. Any tool that makes HTTP requests — Excel, Postman, Node, Go — can query spend and enforce budgets without the Python SDK.
Any language
Providers

All four. Day one.

With correct per-provider token extraction — cache writes, reasoning tokens, context caching, and DeepSeek-R1 thinking tokens.

Anthropic
claude-sonnet-4-6
claude-opus-4-6
claude-haiku-4-5
+ batch pricing
cache_write · cache_read · thinking
OpenAI
gpt-4o · gpt-4o-mini
o1 · o3-mini
+ batch pricing
cached_prompt · reasoning_tokens
Gemini
gemini-2.0-flash
gemini-2.0-flash-lite
gemini-1.5-pro · flash
context_cache · thoughts_tokens
DeepSeek
deepseek-chat (V3)
deepseek-reasoner (R1)
OpenAI-compatible API
cache_hit · cache_miss · reasoning
Who it's for

Built for the whole team.

Not just the engineer who writes the code — every person who cares about AI spend has a workflow.

👩‍💻
Engineer
One import change
Swap your provider import. Every call is automatically tracked, costed, and attributed. No extra code, no middleware, no proxy server.
🖥
DevOps / Operator
CLI from the terminal
Check spend, set budget limits, and inspect traces with the kostrack command. No Python knowledge required beyond installation.
📊
Finance / Management
Dashboards and the API
Open Grafana at localhost:3000 and see spend by project, team, and feature — no code beyond initial setup. Or pull data into Excel or your BI tool via the REST API at :8080/spend.

Start tracking in
five minutes.

docker compose up -d and one import change. That's it.