@spendgraph/sdk
v0.8.3
Published
Track LLM input/output tokens and cost. Three functions, zero dependencies, fail-open.
Maintainers
Readme
@spendgraph/sdk
Track LLM input/output tokens and cost. Three functions, zero dependencies, fail-open.
npm install @spendgraph/sdkimport Anthropic from "@anthropic-ai/sdk";
import { SpendGraph } from "@spendgraph/sdk";
const meter = new SpendGraph({ apiKey: process.env.SPENDGRAPH_API_KEY, baseUrl });
const anthropic = meter.wrap(new Anthropic());Use the client exactly as before. Usage is read off each reply and reported for you, and spend appears on the dashboard within seconds.
What you get
- One line to wire in.
wrap()proxies an Anthropic or OpenAI client and reads the provider's own usage block, cache counts included. - It never throws into your code. Batched, non-blocking, and it drops data rather than take your app down when the meter is having a bad day.
- Nothing about the conversation is sent — the model, the counts, and whatever metadata you attached.
- The whole API, typed.
Spendgraphreaches prompts, tools, stats and events, with retries and error shapes decided once.
Docs
| | | | --- | --- | | Quickstart | Two minutes to your first tracked call | | Tracking | wrap, track and flush | | The client | Spendgraph, and the two halves it reaches | | Errors and retries | What throws, what retries, what never will | | HTTP API | Ingest, stats, events, CSV export | | Integrations | LangChain, LangGraph, Vercel AI | | Budgets and alerts | Thresholds, webhooks, what never happens |
License
Apache-2.0
