SDK
SDK overview
The LLM Cost Tracker SDK is a lightweight TypeScript package that wraps your existing Anthropic, OpenAI, Google Gemini, xAI, DeepSeek, Meta, and Perplexity calls and logs cost data to your dashboard — without changing your response handling or adding latency to your requests. Tag calls with a group to attribute spend across features, teams, or workflows. It also handles budget enforcement, checking spend limits and blocking or warning before a call is made.
Installation
npm install @llmcosttracker/sdkTwo functions
The SDK exports two functions depending on how you call your LLM:
trackedCall()— for standard (non-streaming) callstrackedStream()— for streaming calls
What the SDK does on each call
- Checks the active budget for this user — per-user budget first, tier template as fallback
- If the limit is reached and action is
block, throwsLLMBudgetExceededErrorbefore making the API call - Makes the underlying LLM API call directly to the provider — no proxy, no extra hop
- Reads token counts and latency from the response
- Posts the cost event to your dashboard asynchronously — never blocks the response
- Increments the spend counter for this user
Design principles
- Non-blocking logging — cost events are posted asynchronously and never throw. A logging failure will never surface to your users or break your app.
- Zero response change — both functions return the exact same value as the underlying LLM call. Drop-in replacement.
- No proxy — your API calls go directly to the provider. The SDK reads metadata from the response object after the call resolves. No latency added, no new failure mode.
- No framework required — works with any Node.js or TypeScript project. No LangChain, no special setup.
- Enforcement is optional — if no budget is configured, the SDK behaves exactly as before. Enforcement only activates when you configure a limit in the dashboard.