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

# Bill usage metered in your own system

> Bill usage-based products from quantities your own system already computes: report them to Hyperline as immutable usage events and let it price and invoice them.

This guide shows how to bill usage-based products when your own system already measures consumption. Instead of sending every raw event, you send Hyperline the quantities your system computed for each customer. Hyperline then prices them, adds them to the invoice, and handles collection.

## Context

You already meter usage in your product, data warehouse, or internal billing scripts. You know how many API calls, transactions, or gigabytes each customer consumed, and you want to keep that logic where it is. You only need Hyperline to apply the right price, commitments, and invoicing rules.

Hyperline's usage-based billing always starts from [usage events](https://docs.hyperline.co/docs/usage/send-usage-data.md) and an [aggregator](https://docs.hyperline.co/docs/usage/aggregators.md). With in-house metering, each event carries a quantity you computed, and the aggregator only reads that number back. Hyperline doesn't re-measure anything.

> [card] Example 💡
>
> Your platform computes the number of processed documents per workspace every night. At the end of each month, your billing job knows that the customer Acme processed 12,480 documents. You send Hyperline one event with `quantity: 12480` for November, and Hyperline bills it with your tiered price on the November invoice.

## Prerequisites

Before you begin, make sure you have:

* A usage metric your system already computes per customer, such as API calls, documents, or gigabytes
* Your customers created in Hyperline, ideally with their [external ID](https://docs.hyperline.co/docs/usage/send-usage-data.md#how-hyperline-matches-an-event-to-a-customer) set to the identifier your system uses
* A way to send data to Hyperline: the [events API](https://docs.hyperline.co/api-reference/endpoints/billable-events/ingest-billable-event.md), a [data loader](https://docs.hyperline.co/docs/usage/usage-data-with-connectors.md), or a [CSV import](https://docs.hyperline.co/docs/usage/import-events-csv.md)
* A [test mode](https://docs.hyperline.co/docs/getting-started/sandbox.md) account to validate the setup before going live

## Steps

### 1. Design the usage event

Each time your system reports usage, send a **new event** carrying the quantity it computed. Treat events as immutable: never resend an event to change its quantity. To change a total, send another event (see [step 5](#5-correct-a-quantity)). This keeps a full history of what your system reported and when.

```json Event theme={null}
{
  "customer_id": "acme-workspace-42",
  "timestamp": "2026-11-30T23:00:00.000Z",
  "event_type": "documents_processed",
  "record": {
    "id": "acme-workspace-42_documents_2026-11_run-1",
    "quantity": 12480,
    "period": "2026-11"
  }
}
```

Each field has a specific role:

| Field | What to send |
| - | - |
| `customer_id` | The Hyperline customer ID (`cus_...`) or the customer's external ID. |
| `timestamp` | A date **inside** the billing period the quantity belongs to. Hyperline uses it to select the period to bill. |
| `event_type` | A stable name for the metric, such as `documents_processed`. |
| `record.id` | A unique ID for this report, for example built from the customer, metric, period, and run. Never reuse an ID: Hyperline replaces an existing event that has the same `event_type` and `record.id`. |
| `record.quantity` | The quantity your system computed since its previous report for this period. |

> [!TIP]
>
> Add properties such as `region` or `plan` to the record when you price the same metric differently depending on them. You can then use [aggregator filters](https://docs.hyperline.co/docs/usage/aggregators.md#aggregator-filters) and [price metering filters](https://docs.hyperline.co/docs/products/overview.md#metering-configuration). In that case, send one event per combination.

### 2. Create a sum aggregator

Go to **Usage** > **Aggregators**, then click **New aggregator**:

1. Enter a name, such as "Documents processed".
2. Set **Event type** to the `event_type` you send, for example `documents_processed`.
3. Select the **Sum** operation and the `quantity` property.
4. Set the **Unit name**, such as `documents`. It appears on prices, invoices, and the customer portal.
5. Save the aggregator.

Hyperline adds up every quantity your system reported for the period, so the billed usage is the total of your reports.

> [!NOTE]
>
> If your system reports a cumulative total-to-date instead of the quantity since its previous report, use the **SQL formula** operation with `last(quantity)`. Hyperline then bills only the most recent total of the period. See [SQL formulas](https://docs.hyperline.co/docs/usage/aggregators.md#sql-formulas).

### 3. Create the usage product and subscription

Create a usage product linked to the aggregator, then add it to the customer's subscription. Pricing, commitments, and caps work exactly as with events Hyperline meters itself. Follow [Configure usage-based billing](https://docs.hyperline.co/guides/configure-usage-based-billing.md#2-create-a-usage-based-product) for the detailed steps.

When you add the product to the subscription, keep the **Metering period** set to **Same as payment interval**. Hyperline then bills, for each period, the quantity whose `timestamp` falls inside that period.

### 4. Send the quantities

Choose the method that matches how your system works:

> [card] [API](https://docs.hyperline.co/docs/usage/send-usage-data.md)
>
> Your billing job calls the events API, or the batch endpoint for many customers at once.

> [card] [Data loaders](https://docs.hyperline.co/docs/usage/usage-data-with-connectors.md)
>
> Hyperline runs a query on your database that returns one row per customer and period.

> [card] [CSV import](https://docs.hyperline.co/docs/usage/import-events-csv.md)
>
> You upload a file with one line per customer and period.

With a data loader, make your query return one row per report (for example one row per customer and day) with a unique `id`, the quantity, and a date inside the billing period as `timestamp`.

You can report usage once, when the period is over, or regularly during the period:

* **Once per period**: simplest option. Send one event with the period total. The open invoice shows no usage for the product until you send it.
* **Regular reports**: send a new event every day or every hour with the usage since the previous report. The customer's open invoice, usage tab, and [threshold alerts](https://docs.hyperline.co/docs/usage/aggregators.md#thresholds) stay up to date during the period.

> [!WARNING]
>
> Send the final quantity before the [grace period](https://docs.hyperline.co/docs/invoices/term.md#grace-period) ends. During the grace period, Hyperline still takes new events for the billing period into account. Once it finalizes the invoice, later events no longer change it.

### 5. Correct a quantity

To fix a total, don't modify the event you already sent. Send a new **adjustment event** with its own `record.id`, a `timestamp` inside the same billing period, and the difference as `quantity`. Use a negative quantity to lower the total.

> [card] Example 💡
>
> Your system reported 12,480 documents for Acme in November, but a reprocessing job shows the real total is 12,300. You send a new event with `record.id` `acme-workspace-42_documents_2026-11_adjustment-1` and `quantity: -180`. Hyperline sums both events and bills 12,300 documents on the `open` or grace period invoice.

You can add a property such as `reason` to the record to explain each adjustment.

### 6. Check the result

Validate the setup from the customer page:

1. Open the **Subscriptions** tab and check the usage displayed next to the product.
2. Open the **Invoices** tab and check the `open` invoice for the current period.
3. Click the usage detail icon to see the events behind the total, with the quantities you sent.

## Good to know

* **Customer view**: the usage details and the [customer portal](https://docs.hyperline.co/docs/customers/portal.md) show the totals you sent, not the underlying activity. If customers need a breakdown, send one event per breakdown value (for example per project) instead of a single total.
* **Several subscriptions**: if a customer has several subscriptions with the same usage product, tag each event with its subscription. See [Target usage events to a subscription](https://docs.hyperline.co/guides/target-events-to-subscription.md).
* **Upfront billing**: [upfront metered products](https://docs.hyperline.co/docs/subscriptions/upfront-metering.md) also work with quantities from your system. Hyperline uses the quantities you sent for the closed period to compute the correction line.

## Next steps

> [card] [Send usage data](https://docs.hyperline.co/docs/usage/send-usage-data.md)
>
> Event structure, customer matching, and API limits.

> [card] [Configure aggregators](https://docs.hyperline.co/docs/usage/aggregators.md)
>
> Sum, SQL formulas, filters, and thresholds.

> [card] [Review metering settings](https://docs.hyperline.co/docs/subscriptions/metering.md)
>
> Metering periods and usage windows on subscriptions.

> [card] [Invoice terms](https://docs.hyperline.co/docs/invoices/term.md)
>
> Grace period and invoice finalization.

> [!NOTE]
>
> Is something still unclear? Don't hesitate to reach out to our team via the in-app chat if you need additional support.


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