Skip to main content

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)

Use eventName 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:
Use check with sendEvent: true for atomic check + track operations. This prevents race conditions where usage could be tracked even when the balance is insufficient.

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 the properties field to add context for analytics:
These properties are available in your analytics dashboard and can be queried via the Events API.

Next Steps

Check Access

Verify feature access before operations

Set Up Webhooks

Listen for threshold and limit events