Charging Users Based on Usage
Metering allows you to track specific actions instead of flat wallets. This is ideal if you bill at the end of the month or simply want granular analytics.
[!IMPORTANT] **Understanding theawaitmodel: 1. Telemetry** (settle.events.track()) runs on a non-blocking background memory queue. Do NOT await it. 2. Credit Wallet (settle.wallet.debit()) performs atomic network transactions. You MUST await it.
1. Log Events Liberally
You can track unlimited events. track() uses background memory buffering, meaning it runs at 0ms latency cost to your main execution loop.
typescript
// Just fire and forget. Do NOT await!
settle.events.track({
userId: 'user_123',
eventType: 'API_CALL',
metadata: { endpoint: '/v1/metrics' }
})2. Query Summary Metrics
Need to see what users consumed to generate a custom report or view in your admin portal?
typescript
const summary = await settle.events.getSummary('user_123')
console.log(summary.summary)
// [ { eventType: 'API_CALL', totalQuantity: 15400 } ]