Skip to main content

Drop-in cost tracking for Anthropic, OpenAI, and Google Gemini SDKs — see exactly where your LLM spend goes.

Project description

useleak (python)

Drop-in cost tracking for the Anthropic Python SDK. See exactly where your LLM spend goes — broken down by feature, user, and model.

Install

pip install useleak

Usage

Get a workspace SDK key from Settings → Workspace SDK key in your Leak dashboard. Set it as LEAK_KEY in your env (alongside ANTHROPIC_API_KEY).

import os
from useleak import Anthropic

client = Anthropic()  # picks up ANTHROPIC_API_KEY + LEAK_KEY from env

response = client.messages.create(
    model="claude-opus-4-7",
    feature="icp-scoring",     # ← the one extra param Leak needs
    user="user_123",            # optional but lets you group by customer
    max_tokens=1024,
    messages=[{"role": "user", "content": "..."}],
)

print(response.content[0].text)

That's it. Every call gets tracked to your Leak dashboard within a few seconds: model, tokens in/out, cost, feature, user, request ID.

API

useleak.Anthropic accepts every kwarg the official anthropic.Anthropic accepts, plus two of its own:

Parameter Default Description
leak_key LEAK_KEY env Your workspace SDK key (lk_live_...)
leak_url https://useleak.cloud/api/ingest Ingest endpoint, override only if self-hosting

client.messages.create(...) accepts every kwarg the Anthropic SDK accepts, plus three of its own:

Parameter Required Description
feature recommended The feature in your app that triggered this call ("icp-scoring", "playground", etc.)
user optional An end-user identifier — lets you see who is burning tokens
api_key_label optional Free-form label like "Production" / "Staging"

Tracking is async and non-blocking. If useleak.cloud is down, your Anthropic call still succeeds — Leak failures never propagate.

What it tracks

  • model
  • input tokens / output tokens
  • USD cost (computed locally from the Anthropic price table)
  • feature, user, api_key_label (your tags)
  • Anthropic request ID

It does not send prompts, responses, or any message content.

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

useleak-0.3.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

useleak-0.3.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file useleak-0.3.0.tar.gz.

File metadata

  • Download URL: useleak-0.3.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for useleak-0.3.0.tar.gz
Algorithm Hash digest
SHA256 13c74a628aeab79283cf1fad33b140d00f4f8c449b75f0ef82573c128d6f2c5a
MD5 161003da5b45de3a6562bf9d0d50992a
BLAKE2b-256 544e43d5cf17bac8098ebf6b4f4ccb08e3547f7b954dea6f457d6f6ad4b4f1d8

See more details on using hashes here.

File details

Details for the file useleak-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: useleak-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for useleak-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60d303271bd258b04eda7166336e771a27de4fa08595147822a33ed3c79e0451
MD5 8d2c1e02a25f5f1b0108d53b4f2111fa
BLAKE2b-256 9427fab303402f58fbe540a93d34570a59fbd116123051a86de3806a3b07470b

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