useleak
v0.4.0
Published
Drop-in cost tracking for Anthropic, OpenAI, and Google Gemini SDKs — see exactly where your LLM spend goes.
Maintainers
Readme
useleak (typescript)
Drop-in cost tracking for the Anthropic TypeScript SDK. See exactly where your LLM spend goes — broken down by feature, user, and model.
Install
pnpm add useleak
# or
npm install useleak
# or
yarn add useleakUsage
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 Anthropic from "useleak";
const client = new Anthropic(); // picks up ANTHROPIC_API_KEY + LEAK_KEY
const response = await 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: "..." }],
});
console.log(response.content);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
new Anthropic(opts) accepts every option the official @anthropic-ai/sdk
accepts, plus two of its own:
| Option | Default | Description |
|---|---|---|
| leakKey | LEAK_KEY env | Your workspace SDK key (lk_live_...) |
| leakUrl | https://useleak.cloud/api/ingest | Ingest endpoint, override only if self-hosting |
client.messages.create({...}) accepts every parameter the Anthropic SDK accepts,
plus three of its own:
| Field | 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 (using fetch with keepalive: true).
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.
Runtimes
Works on Node 18+, Bun, Deno, Cloudflare Workers, Vercel Edge — anywhere fetch exists.
License
MIT
