Tracking Events

Track usage events with the TypeScript SDK

Track usage events to monitor AI consumption.

Basic Tracking

await client.track.trackUsage({
  customerId: 'customer_123',
  eventType: 'model_call',
  model: 'gpt-4',
  provider: 'openai',
  inputTokens: 100,
  outputTokens: 50,
  totalTokens: 150,
});

Advanced Tracking

await client.track.trackUsage({
  customerId: 'customer_123',
  eventType: 'model_call',
  model: 'gpt-4',
  provider: 'openai',
  inputTokens: 100,
  outputTokens: 50,
  totalTokens: 150,
  costCents: 25,
  latencyMs: 1200,
  properties: {
    user_id: 'user_456',
    team_id: 'team_eng',
  },
  idempotencyKey: 'req_abc123',
});

Next Steps

On this page