LLMtrack / SDK

Official SDKs for Node and Python

Track every LLM request's cost with one line of code. Never throws, never blocks, retries safely, and counts reasoning tokens — so your cost data is complete and your app is untouched.

npm install llmtrack
pip install llmtrack-sdk

Quickstart

  1. Install the package.
  2. Initialize it with your ingestion key.
  3. Track after your LLM call.
import { LLMtrack } from 'llmtrack';

const llmtrack = new LLMtrack({ apiKey: process.env.LLMTRACK_API_KEY });

// after your LLM call — fire-and-forget, never throws, never blocks
llmtrack.track({
  provider: 'openai',
  model: 'gpt-5.6-sol',
  feature: 'chat-completion',
  promptTokens: 1200,
  completionTokens: 480,
  reasoningTokens: 3100,
});

Examples

OpenAI completion

const response = await openai.chat.completions.create({
  model: 'gpt-5.6-sol',
  messages,
});

llmtrack.track({
  provider: 'openai', model: response.model, feature: 'chat-completion',
  promptTokens: response.usage?.prompt_tokens,
  completionTokens: response.usage?.completion_tokens,
  reasoningTokens: response.usage?.completion_tokens_details?.reasoning_tokens,
});

Anthropic completion

const message = await anthropic.messages.create({
  model: 'claude-sonnet-5', max_tokens: 1024, messages,
});

llmtrack.track({
  provider: 'anthropic', model: message.model, feature: 'chat-completion',
  promptTokens: message.usage.input_tokens,
  completionTokens: message.usage.output_tokens,
  reasoningTokens: message.usage.thinking_tokens,
});

Why use the SDK?

  • Never throws: track() swallows every failure into a warning callback.
  • Auto-retry: network, timeout, and 5xx failures retry with stable idempotency keys, so retries can never double-count cost.
  • Client-side validation: enforces 8 KB metadata and non-negative integer tokens.
  • Fully typed: typed constructors, event fields, callbacks, errors, and warnings.

Prefer raw HTTP or another language? The full API reference documents the endpoint every SDK uses — Go, Ruby, PHP, Rust and anything else can integrate with one POST.

Constructor options

OptionTypeDefaultDescription
apiKeystring— (required)LLMtrack ingestion key.
baseUrlstringhttps://llm-track.comAPI base URL.
environmentstringproductionDefault event environment.
onError(error) => voidundefinedReceives validation errors.
onWarning(warning) => voidconsole.warnReceives swallowed delivery failures and API warnings.
enabledbooleantrueTurns tracking on or off.
timeoutMsnumber5000Request timeout in milliseconds.
maxRetriesnumber3Maximum network, timeout, and 5xx retries.

Event fields

FieldTypeRequiredDescription
providerstringRequiredNon-empty provider name.
modelstringRequiredNon-empty model name.
featurestring | nullOptionalTakes precedence over metadata.feature; defaults to unknown.
customerId / customer_idstring | nullOptionalCustomer attribution.
customerName / customer_namestring | nullOptionalCustomer attribution.
environmentstring | nullOptionalDefaults to production.
promptTokens / prompt_tokensinteger | nullOptionalNon-negative token count.
completionTokens / completion_tokensinteger | nullOptionalNon-negative token count.
totalTokens / total_tokensinteger | nullOptionalComputed from prompt + completion + reasoning when omitted or null.
reasoningTokens / reasoning_tokensinteger | nullOptionalNon-negative reasoning token count.
cachedInputTokens / cached_input_tokensinteger | nullOptionalNon-negative cached input token count.
cacheWriteTokens / cache_write_tokensinteger | nullOptionalNon-negative cache-write token count.
latencyMs / latency_msinteger | nullOptionalNon-negative latency in milliseconds.
statusstringOptionalsuccess, error, timeout, or cancelled; defaults to success.
metadataobjectOptionalArbitrary JSON object, at most 8 KB (8192 bytes) serialized.

Errors and warnings

CodeMeaningFix
INVALID_API_KEYThe key is missing or invalid.Use an active LLMtrack ingestion key.
REVOKED_API_KEYThe key was deleted or revoked.Create and use a new key.
INACTIVE_API_KEYThe key is deactivated.Reactivate it or use an active key.
INVALID_PAYLOADOne or more event fields are invalid.Correct the fields identified by validation.
QUOTA_EXCEEDEDThe plan event allowance is exhausted.Wait for reset or upgrade the workspace.
PLAN_INACTIVEThe workspace plan cannot ingest events.Restore an active plan.
NETWORK_ERRORThe SDK could not reach LLMtrack.Check connectivity; the SDK retries automatically.

Warnings

  • dashboard_visible: false: a free-plan source binding mismatch is accepted and counts against usage, but is hidden. Match the provider, model, and feature bound to the key.
  • pricing_status: "unknown_model": no active pricing row exists, so cost is 0; this is different from a genuine calculated zero.

Free-plan source visibility

Each free-plan ingestion key is bound to one normalized provider/model/feature triple. A mismatch is not an error: the event is accepted and counts against included usage or PPE credits, but is hidden from the dashboard with dashboard_visible: false and visibility_reason: free_source_mismatch. To avoid it, send the same provider, model, and feature shown for the selected key; the top-level feature wins over metadata.feature. Paid users have unrestricted source visibility according to current product rules.

Troubleshooting

  • Events not appearing: check the free-key provider/model/feature binding and the response's dashboard visibility fields.
  • Cost is 0: check for pricing_status: "unknown_model".
  • Key rejected: revoked keys need replacement; inactive keys need reactivation or replacement.
  • Nothing happens: confirm enabled is not false and LLMTRACK_API_KEY is the correct environment variable.

Track your first request