Sentry for AI costs. Track every LLM call's cost, tokens, and latency with one line of code.
Project description
costkey
Sentry for AI costs. Track every LLM call's cost, tokens, and latency with one line of code.
Install
pip install costkey
Quick Start
import costkey
costkey.init(dsn="https://ck_your_key@costkey.dev/your-project")
# That's it. Every AI call is now tracked automatically.
# Works with OpenAI, Anthropic, Google Gemini, Azure OpenAI.
How It Works
CostKey patches httpx and requests — the HTTP clients that every AI SDK uses under the hood. When your code calls any AI provider, CostKey automatically:
- Detects the AI provider from the URL
- Extracts token usage from the response
- Captures a stack trace (which function, which file, which line)
- Computes cost using built-in pricing for 30+ models
- Ships the event to your CostKey dashboard (async, non-blocking)
Tracing
with costkey.start_trace(name="POST /api/search"):
intent = classify_intent(query)
results = search(query)
summary = summarize(results)
# All 3 AI calls grouped under one trace
Manual Context
with costkey.with_context(task="summarize", team="search"):
response = openai.chat.completions.create(...)
Privacy
- Never captures API keys — request headers are never read
- Auto-scrubs credentials from request/response bodies
before_sendhook for custom PII scrubbing
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file costkey-0.1.0.tar.gz.
File metadata
- Download URL: costkey-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
477eaf6c9271a6d6e27763ce94ded64579de36de8de9468fd5106da5b1769f43
|
|
| MD5 |
cc5fe74dba13dbc8060888a175c9ffc4
|
|
| BLAKE2b-256 |
20f7173e0535ad55962bbd703cfb254defb3dbefb50eca432a667770c247a8ff
|
File details
Details for the file costkey-0.1.0-py3-none-any.whl.
File metadata
- Download URL: costkey-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14dd723a1f408d403edff943c3353b7ea6de305d8171b0f56f45d666882c43a8
|
|
| MD5 |
816f66652eb72ac2792a72212fd45aaa
|
|
| BLAKE2b-256 |
0dacffd36c26e3c8cac9f1f4b27b0568a935f67e7c0dcb83759720b8a02c6314
|