> ## Documentation Index
> Fetch the complete documentation index at: https://zenskar.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Concepts: How usage events work

> This document explains usage events, how usage-event collections, data schemas, and API slugs shape them, and the ways that usage events reach Zenskar.

## Usage events

> [accordion] Walkthroughs
>
> 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.
>
> | Walkthrough | What it shows |
> | - | - |
> | [End-to-end walkthrough: How usage works](https://zenskar.com/docs/20260301/zenskar-modules/usage/walkthroughs/usage.md) | This example-based document shows how the API calls of one customer become usage events, and how a billable metric turns those usage events into one result for each billing period. |

> [accordion] Map of concepts
>
> | Concept | What it is | What it is used for |
> | - | - | - |
> | [Usage event](#usage-events-reports-of-usage) | A report that you provide to Zenskar about the usage of one customer at one point in time | A billable metric aggregates the usage events with a calculation type. |
> | [Usage-event collection](#usage-events-reports-of-usage) | A named set of usage events of one kind | Each usage event belongs to one usage-event collection. |
> | [Data schema](#data-schemas-the-shape-of-a-usage-event) | The list of fields of the usage events of a particular usage-event collection | A usage event has the fields that the data schema of its usage-event collection lists. |
> | [Root field](#root-fields-what-zenskar-requires-in-every-usage-event) | One of the two fields that Zenskar requires at the top level of every usage event: `customer_id` and `timestamp` | A usage event carries the root fields at its top level. |
> | [Data field](#data-fields-the-details-that-you-add) | A field that you add to a data schema, with a name and one data type | A usage event carries its data fields in its `data` object. |
> | [API slug](#api-endpoints-where-usage-events-are-delivered) | The part of the API endpoint of a usage-event collection that identifies it | Each usage-event collection has one API slug. |

> [accordion] Related modules
>
> Usage uses the following modules:
>
> | Module | Details |
> | - | - |
> | [Customers](https://zenskar.com/docs/20260301/zenskar-modules/customers/concepts.md#customers-who-you-bill) | Each usage event names its customer in the `customer_id` root field. |
> | [API keys](https://zenskar.com/docs/20260301/zenskar-modules/settings/api-keys.md) | A request to the API endpoint of a usage-event collection carries an API key. |

## Usage events: reports of usage

A **usage event** is a report that you provide to Zenskar about the [usage](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#usage) of one customer at one point in time.

What a usage event reports is up to you. For example:

| A usage event reports | Example |
| - | - |
| One action | One API call |
| A count over a short time | The number of API calls of a customer in one minute |
| An amount at one moment | The number of seats in use at noon |
| A size | The gigabytes of one file transfer |

A [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) aggregates the usage events with a [calculation type](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#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](#data-schemas-the-shape-of-a-usage-event) and one [API slug](#api-endpoints-where-usage-events-are-delivered). 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.

```mermaid theme={null}
---
config:
  class:
    hideEmptyMembersBox: true
  themeCSS: ".divider ~ .divider { display: none; }"
---
classDiagram
  direction LR
  class Collection["Usage-event collection"]
  class Event["Usage event"]
  class Schema["Data schema"]
  class Slug["API slug"]
  Collection "1" --> "0..*" Event : Holds
  Collection "1" --> "1" Schema : Has
  Collection "1" --> "1" Slug : Has
```

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](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/historical-usage.md).

See [Create a usage-event collection](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#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](#root-fields-what-zenskar-requires-in-every-usage-event) and zero or more [data fields](#data-fields-the-details-that-you-add). A usage event carries the root fields at its top level, and its data fields in its `data` object.

```mermaid theme={null}
---
config:
  class:
    hideEmptyMembersBox: true
  themeCSS: ".divider ~ .divider { display: none; }"
---
classDiagram
  direction LR
  class Schema["Data schema"]
  class Root["Root field"]
  class Data["Data field"]
  Schema "1" --> "2" Root : Lists
  Schema "1" --> "0..*" Data : Lists
```

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:

```json theme={null}
{
  "customer_id": "c01",
  "timestamp": "2025-07-06 09:15:13",
  "data": {
    "region": "eu-west",
    "size_kb": 12.5
  }
}
```

### 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](https://clickhouse.com/docs/sql-reference/data-types) 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.

| Data type | Holds | Example value |
| - | - | - |
| String | Text | `"eu-west"` |
| Int64 | A whole number | `250` |
| Float64 | A number with a decimal part | `12.5` |
| Date32 | A date | `"2025-07-06"` |
| DateTime64 | A date and a time | `"2025-07-06 09:15:13"` |
| UUID | A universally unique identifier | `"3f2b6c1e-8a4d-4b7e-9c2a-5d1e0f6a7b8c"` |
| Bool | True or false | `true` |

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](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#add-a-data-field).

## API endpoints: where usage events are delivered

```mermaid theme={null}
sequenceDiagram
  autonumber
  participant E as Usage event
  participant A as API slug
  participant C as Usage-event collection
  E->>A: Arrives at the API endpoint<br/>that ends with the API slug
  A->>C: Identifies the usage-event collection
  C->>C: Stores the usage event as it arrives
```

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](https://developer.mozilla.org/en-US/docs/Glossary/REST) API. The API endpoint is `https://api.zenskar.com/usage/{api_slug}`, where `{api_slug}` is the API slug:

| | API endpoint | API slug |
| - | - | - |
| What it is | The web address to which you send the usage events of a usage-event collection | The last part of the API endpoint, which identifies the usage-event collection |
| Example | `https://api.zenskar.com/usage/api_calls` | `api_calls` |

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](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#organization). See [API keys](https://zenskar.com/docs/20260301/zenskar-modules/settings/api-keys.md).

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.

| Way | How it works | When it fits | Task |
| - | - | - | - |
| A [CSV](https://www.rfc-editor.org/rfc/rfc4180) file | A CSV file holds one row for each usage event. Zenskar checks every row against the data schema before it stores any row. If one row fails the check, Zenskar stores none of the rows. | It fits a one-time import, such as past usage. | [Upload usage events from a CSV file](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#upload-usage-events-from-a-csv-file) |
| One usage event at a time, manually | You enter one usage event, with a value for each root field. | It fits a test or a few usage events. | [Add a single usage event](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#add-a-single-usage-event) |
| A request to the API endpoint of the usage-event collection | A request carries an API key, and one usage event or a list of usage events. | It fits continuous sending from your systems. | [Send usage events through the API](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#send-usage-events-through-the-api) |
| [S3 ingestion](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#s3-ingestion) | Files in a [folder](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-folders.html) of an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) bucket hold the usage events. Zenskar reads each file when it arrives in the folder. | It fits regular files of usage from your systems. | [Set up S3 ingestion for a usage-event collection](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#set-up-s3-ingestion-for-a-usage-event-collection) |

If your usage is in a [data source](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#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](https://en.wikipedia.org/wiki/Table_\(database\)) 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](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#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.

```mermaid theme={null}
sequenceDiagram
  autonumber
  participant E as Usage event
  participant D as Data schema
  participant C as Usage-event collection
  E->>D: Is checked against the fields of the data schema
  D->>C: Becomes one row, with one column for each field
  Note over C: customer_id | timestamp | data.region | data.size_kb
```

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](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/s3-ingestion.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.