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
The ID of the service the usage occurred on.
The ID of the subscription this usage belongs to. Must belong to the specified
serviceId and userId.The ID of the subscriber who generated the usage.
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.The amount consumed. Pass as a decimal string (e.g.
"1000.000000") or a number. Must be a non-negative value.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.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 HTTP201 Created with the new usage event object and all related records.
The newly recorded usage event with related records.
201 — Usage event recorded
Example Request
Error Codes
| Status | Message | Condition |
|---|---|---|
400 Bad Request | serviceId is required. | serviceId was omitted. |
400 Bad Request | subscriptionId is required. | subscriptionId was omitted. |
400 Bad Request | userId is required. | userId was omitted. |
400 Bad Request | eventKey is required. | eventKey was omitted. |
400 Bad Request | quantity is required. | quantity was omitted. |
400 Bad Request | Invoice does not match the usage event service and user. | The provided invoiceId belongs to a different service or user. |
404 Not Found | Subscription was not found for the service and user. | The subscription does not exist or does not belong to the specified service and user. |
409 Conflict | A database record with these unique fields already exists. | The subscriptionId + eventKey combination has already been recorded. |
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.