Commet
  • Pricing
Log InTry out
Introduction

Quickstart

Learn

Track UsageAI Token BillingSeat Management

Resources

SDK ReferenceError HandlingTestingCLI

Plugins

Better Auth
DocumentationKnowledge BaseBuild with AIAPI ReferenceWebhooks

Track Usage

Track consumption events for metered features with the Commet SDK.

Every metered feature has an event code. Your application sends events with that code, and Commet aggregates them for billing at the end of the period.

Usage event components

ComponentDescriptionExample
FeatureEvent code of a metered featureapi_calls, storage_gb
ValueQuantity consumed1, 0.5, 100
CustomerWho consumed itcustomerId: "user_123"
Idempotency KeyPrevents duplicate events"req_abc123"
TimestampWhen it happened (defaults to now)"2026-01-15T10:00:00Z"

Setting up event codes

When you create a metered feature in the dashboard, you define its event code. Go to Features, click Create Feature, select Metered, and enter the event code.

Event code conventions

Good Event CodesBad Event Codes
api_callsfeature1
storage_gbmetric
emails_sentusage
compute_minutesx

Use snake_case. Be descriptive — this is what appears in code.

Track a single event

await commet.usage.track({
  customerId: "user_123",
  feature: "api_calls",
  value: 1,
})

Pass either a Commet ID (cus_xxx) or your external ID as customerId.

Track in batches

More efficient for high-volume tracking. Maximum 100 events per batch request.

await commet.usage.trackBatch({
  events: [
    { customerId: "user_123", feature: "api_calls", value: 1 },
    { customerId: "user_456", feature: "api_calls", value: 3 },
    { customerId: "user_123", feature: "storage_gb", value: 0.5 },
  ],
})

Parameters

ParameterTypeRequiredDescription
featurestringYesEvent code of a metered feature. Only lowercase letters, numbers, and underscores (a-z0-9_)
customerIdstringYesCommet customer ID (cus_xxx) or your external ID
valuenumberNoQuantity consumed. Must be >= 0. Defaults to 1
idempotencyKeystringNoPrevents duplicate events
timestampstringNoISO 8601 datetime. Defaults to now
propertiesarrayNoKey-value metadata for debugging

Idempotency

Prevent duplicate charges by passing an idempotencyKey. Commet rejects events with a key that was already recorded for the same customer.

await commet.usage.track({
  customerId: "user_123",
  feature: "api_calls",
  value: 1,
  idempotencyKey: "req_abc123",
})

Related

  • AI Token Billing — Automatically track and charge for AI model tokens
  • Configure Features — Create metered features and event codes
  • Consumption Models — How usage is billed across metered, credits, and balance

How is this guide?

Upgrade and Downgrade Plans

How customers change plans through the Customer Portal and dashboard.

AI Token Billing

Automatically measure and charge for AI token usage with model-aware pricing and configurable margins.

On this page

Usage event components
Setting up event codes
Event code conventions
Track a single event
Track in batches
Parameters
Idempotency
Related