Skip to main content

Usage events

You can start with a walkthrough instead of reading this document first. A walkthrough is the practical extension of the concepts in this document. It puts them into practice through one example with concrete values. Each part of the walkthrough explains the concepts that its steps apply and links to the sections that cover them.

Usage events: reports of usage

A usage event is a report that you provide to Zenskar about the usage of one customer at one point in time. What a usage event reports is up to you. For example: A billable metric aggregates the usage events with a calculation type, such as count, sum, or maximum. A usage-event collection is a named set of usage events of one kind. Each usage event belongs to one usage-event collection, such as api_calls for API calls. Each usage-event collection has one data schema and one API slug. A usage event has the fields that the data schema of its usage-event collection lists. A usage-event collection must exist before it can receive usage events.

This conceptual diagram shows what a usage-event collection has.

Zenskar keeps each usage event as it arrives. A usage event cannot be edited or deleted. A usage-event collection cannot be deleted either. See How-to guides: Correct historical usage. See Create a usage-event collection.

Data schemas: the shape of a usage event

A data schema is the list of fields of the usage events of a particular usage-event collection. Each usage-event collection has one data schema. A data schema lists the two root fields and zero or more data fields. A usage event carries the root fields at its top level, and its data fields in its data object.

This conceptual diagram shows what a data schema lists.

The following usage event of the usage-event collection api_calls has both root fields and two data fields:

Root fields: what Zenskar requires in every usage event

A root field is one of the two fields that Zenskar requires at the top level of every usage event: customer_id and timestamp. customer_id identifies the customer of the usage event. Its data type is always String. A billable metric matches its value to a customer in Zenskar. timestamp is the moment of the usage. Its data type is always DateTime64. Zenskar orders the usage events of a usage-event collection by timestamp.

Data fields: the details that you add

A data field is a field that you add to a data schema, with a name and one data type. Each usage event holds the values of its data fields in its data object. A usage event can leave a data field empty. Data fields hold the details of the usage, such as the region of an API call or the size of a file. Each data field has one of the following data types. The examples use the formats that the API accepts. You can add a data field to a data schema after the usage-event collection is created. A data field cannot be removed or renamed, and its data type cannot change. See Add a data field.

API endpoints: where usage events are delivered

This conceptual diagram shows how a usage event sent through the API reaches its usage-event collection.

An API slug is the part of the API endpoint of a usage-event collection that identifies it. Each usage-event collection has its own API endpoint, as in a REST API. The API endpoint is https://api.zenskar.com/usage/{api_slug}, where {api_slug} is the API slug: Zenskar stores each usage event that arrives at the API endpoint in its usage-event collection. Each request carries an API key of the organization. See API keys. By default, the API slug follows the name of the usage-event collection, in lowercase, with an underscore for each space. A different API slug can be chosen when the usage-event collection is created. The API slug is unique in the organization, so it tells apart two usage-event collections that have the same name. A billable metric names a usage-event collection by its API slug. The API slug cannot change after the usage-event collection is created.

Ways to send usage events

Usage events reach a usage-event collection in four ways. Zenskar stores the usage events of all four ways in the same usage-event collection, and a billable metric reads them in the same way. If your usage is in a data source, a billable metric aggregates it without usage events.

Usage events as rows and columns

Zenskar stores each usage-event collection as a row-and-column representation: each usage event is one row, and each field of the data schema is one column. A root field keeps its name, and a data field becomes a column named data. followed by its name, such as data.region. A billable metric reads these columns, such as data.size_kb in a query of the SQL builder. Every way to send usage events ends in the same kind of row. Zenskar checks each usage event against the data schema before it stores the row.

This conceptual diagram shows how Zenskar stores a usage event as one row of its usage-event collection.

S3 ingestion: usage events from files in Amazon S3

S3 ingestion reads usage events from CSV files in the Amazon S3 bucket of your organization. Each usage-event collection that uses S3 ingestion has its own folder in the bucket. For example, Zenskar stores the rows of the file api_calls/2026-10-01.csv as usage events of the usage-event collection whose folder is api_calls. See Concepts: How S3 ingestion works.