SDK
trackedCall()
Wraps a standard (non-streaming) LLM call and logs cost data to your dashboard. Supports Anthropic, OpenAI, Google Gemini, and any OpenAI-compatible provider (DeepSeek, xAI, Perplexity). Returns the identical response as the underlying call.
Usage
import { trackedCall } from '@llmcosttracker/sdk'const response = await trackedCall({client: anthropic, group: 'summarize', userId: session.userId, tier: session.plan, apiKey: 'lct_live_your_key_here', params: {model: 'claude-sonnet-4-6', messages, max_tokens: 1024,},})Parameters
Returns
The exact response from the underlying LLM call — identical to calling the provider's API directly.
Error handling
If logging fails for any reason, the error is caught silently. The function always returns the LLM response — a logging failure will never throw or affect your application.
The one exception is budget enforcement. If a budget is configured with action: "block" and the user has reached their limit, trackedCall() throws LLMBudgetExceededError before making the underlying API call. Catch it explicitly:
import { trackedCall, LLMBudgetExceededError } from '@llmcosttracker/sdk'try {const response = await trackedCall({ client, params, apiKey, userId, tier })return response} catch (err) {if (err instanceof LLMBudgetExceededError) {// return a graceful response to your userreturn { error: 'limit_reached', message: 'Monthly AI usage limit reached.' }}throw err}See Handling blocks for full details including reset date calculation and the warning callback.
Next: trackedStream() →