Skip to main content
Usage events track what a subscriber consumes under a subscription so Retempo can aggregate metered billing accurately. Each event records a discrete action — an API call, a generated token, a processed document — identified by an eventKey and a quantity. You can attach usage events to an open invoice for precise per-period billing, or leave invoiceId unset and reconcile later.

Request Body

string
required
The ID of the service the usage occurred on.
string
required
The ID of the subscription this usage belongs to. Must belong to the specified serviceId and userId.
string
required
The ID of the subscriber who generated the usage.
string
required
A string identifier for the type of usage being recorded (e.g. api_request, token_generated). The combination of subscriptionId + eventKey must be unique — submitting the same pair twice returns a 409.
string | number
required
The amount consumed. Pass as a decimal string (e.g. "1000.000000") or a number. Must be a non-negative value.
string
The ID of an invoice to associate with this usage event. If provided, the invoice must belong to the same serviceId and userId. Optional — omit to reconcile usage to an invoice later.
string
An ISO 8601 datetime string for when the usage occurred. Defaults to the time of the API call if omitted. Pass this to backfill historical usage.

Response

A successful request returns HTTP 201 Created with the new usage event object and all related records.
object
The newly recorded usage event with related records.

201 — Usage event recorded

Example Request

Error Codes

The combination of subscriptionId + eventKey must be unique. Use different eventKey values to track different action types within the same subscription. Duplicate submissions return a 409 error.
Pass occurredAt in ISO 8601 format to backfill usage events that occurred before the API call. This lets you report usage accurately even when your system processes events asynchronously or in batches.