TypeScript SDK
The @trakr/monitor package automatically instruments Anthropic and OpenAI clients with zero changes to your existing code.
Installation
pnpm add @trakr/monitor
# or
npm install @trakr/monitor
Initialization
import Trakr from '@trakr/monitor';
Trakr.init({ apiKey: process.env.TRAKR_API_KEY });
If TRAKR_API_KEY is set in the environment, you can call Trakr.init() with no arguments.
Automatic instrumentation
After init, all LLM calls are captured automatically:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const message = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
Manual workflow wrapping
For multi-step workflows, use startRun():
import Trakr from '@trakr/monitor';
Trakr.init();
const run = Trakr.startRun('invoice-extractor');
try {
const result = await extractInvoice(document);
await run.end({ status: 'success' });
return result;
} catch (error) {
await run.end({
status: 'error',
errorMessage: error instanceof Error ? error.message : 'Unknown error',
});
throw error;
}
Framework examples
Next.js API routes
Initialize in a shared module imported at startup:
// lib/trakr.ts
import Trakr from '@trakr/monitor';
Trakr.init();
Node.js scripts
Call flush() before process exit to ensure all events are uploaded:
await Trakr.flush();
Configuration options
| Option | Default | Description |
| --- | --- | --- |
| apiKey | — | Required. SDK API key from dashboard |
| endpoint | https://app.trakr.run/api/ingest | Override ingest URL |
| batchSize | 10 | Events per batch upload |
| flushIntervalMs | 2000 | Max ms between flushes |
| loopDetectionThreshold | 5 | Same tool calls before flagging |
| disabled | false | Disable SDK entirely |
| debug | false | Log SDK activity to console |