POST /api/v1/invoices.
What is a usage event?
A usage event represents a single metered action taken by a subscriber. Each event captures two key pieces of information:eventKey— a string identifier for the type of action (e.g.'token_generated','api_request','gb_stored'). You define these keys to match the billable dimensions of your service.quantity— the number of units consumed in this event (e.g.1000tokens,5.25gigabytes,1API call).
subscriptionId, and to the service and subscriber via serviceId and userId. The subscription must be in an ACTIVE state before you can record events against it.
For USAGE_BASED plans, usage events are the source of truth for what gets billed — you sum the event quantities at the end of the billing period, compute the invoice amount, and create the invoice with that value. Retempo stores the amount you provide; it does not automatically aggregate events into an invoice. For FIXED_RECURRING plans, you can still record usage events for analytics and visibility, but they do not affect the billed amount.
Recording a usage event
Send aPOST request to /api/v1/usage-events each time a subscriber consumes a unit of your service. The required fields are serviceId, subscriptionId, userId, eventKey, and quantity. The optional occurredAt timestamp defaults to the current time if you omit it; invoiceId is also optional and lets you link the event to a specific invoice.
- The
subscriptionIdmust belong to both the givenserviceIdanduserId. Mismatches return a validation error. - If you supply an
invoiceId, it must be associated with the same service and user. - The subscription must be
ACTIVEat the time of the request.
Linking events to invoices
The optionalinvoiceId field lets you attach a usage event directly to an existing invoice. This is useful when you want to pre-associate events with a specific billing period or invoice as they happen, rather than looking them up at invoice-creation time.
Each combination of
subscriptionId + eventKey must be unique. Use distinct eventKey values for different action types on the same subscription. For example, if a subscriber generates tokens and makes API requests, record separate events with token_generated and api_request rather than reusing the same key.Common eventKey patterns
ChooseeventKey values that clearly describe the billable action and map directly to the pricing dimensions of your service. Retempo does not enforce a fixed schema — you define the keys that make sense for your product.
Here are common patterns used by API providers and AI agent services:
eventKey | Description | Example quantity |
|---|---|---|
api_request | A single inbound API call | 1 |
token_generated | Tokens produced by an LLM | 8192 |
token_consumed | Total tokens processed (input + output) | 12500 |
gb_stored | Gigabytes of data stored | 2.75 |
gb_transferred | Gigabytes of data transferred out | 0.5 |
task_completed | A discrete agent task or job run | 1 |
image_rendered | Images generated or processed | 25 |
compute_second | Seconds of compute time consumed | 300 |
eventKey in the same request cycle. This keeps your billing data granular and lets you price each dimension independently.