Skip to main content

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:

  1. Detects the AI provider from the URL
  2. Extracts token usage from the response
  3. Captures a stack trace (which function, which file, which line)
  4. Computes cost using built-in pricing for 30+ models
  5. 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_send hook for custom PII scrubbing

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

costkey-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

costkey-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

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

Hashes for costkey-0.1.0.tar.gz
Algorithm Hash digest
SHA256 477eaf6c9271a6d6e27763ce94ded64579de36de8de9468fd5106da5b1769f43
MD5 cc5fe74dba13dbc8060888a175c9ffc4
BLAKE2b-256 20f7173e0535ad55962bbd703cfb254defb3dbefb50eca432a667770c247a8ff

See more details on using hashes here.

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

Hashes for costkey-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14dd723a1f408d403edff943c3353b7ea6de305d8171b0f56f45d666882c43a8
MD5 816f66652eb72ac2792a72212fd45aaa
BLAKE2b-256 0dacffd36c26e3c8cac9f1f4b27b0568a935f67e7c0dcb83759720b8a02c6314

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page