Overview
The/track endpoint records usage events for your metered features. Use it to:
- Track API calls, messages, or other usage-based features
- Deduct from customer balances in real-time
- Bill customers for overage usage
- Log events with custom properties for analytics
Quick Start
Parameters
string
required
The ID of the customer whose usage to track.
string
The ID of the feature to track. Use either
featureId or eventName.string
Event name to track usage for. Use instead of
featureId when a single event should update multiple features.string
The ID of the entity for entity-scoped tracking (e.g., per-workspace usage).
number
default:"1"
The amount of usage to record. Use negative values to credit balance (e.g., when removing a seat).
object
Additional properties to attach to the usage event for analytics and debugging.
Response
Common Use Cases
Track API Calls
Track Variable Usage (Tokens, Storage, etc.)
Event-Based Tracking (One Event, Multiple Features)
UseeventName to track a single event that updates multiple feature balances:
Credit Usage (Negative Values)
Use negative values to add back to a customer’s balance:Entity-Scoped Tracking (Per-Workspace)
Idempotency
For critical operations, use an idempotency key to prevent duplicate tracking:Idempotency keys are automatically handled for you in most cases. Only use manual idempotency keys for critical operations where duplicate tracking would cause issues.
Error Handling
Check Before Track
To prevent exceeding limits, check access before tracking:Batch Tracking
For high-volume scenarios, batch multiple track calls:Query Parameters
boolean
default:"false"
Bypass cache for fresh balance data.
string[]
Expand related objects. Supports:
"balance.feature"Analytics and Reporting
Use theproperties field to add context for analytics:
Related Endpoints
- Check Endpoint - Verify access before tracking
- Webhooks - Listen for usage threshold events
- Events API - Query historical usage data
Next Steps
Check Access
Verify feature access before operations
Set Up Webhooks
Listen for threshold and limit events