Usage-based billing charges customers for what they actually consume rather than a fixed recurring amount. Borga implements this through two primitives: meters, which define what to measure and how to aggregate it, and events, which are the raw usage records you send from your application. At the end of each billing period, Borga totals the events for each customer and generates an invoice based on the metered price you configured.Documentation Index
Fetch the complete documentation index at: https://docs.borga.is/llms.txt
Use this file to discover all available pages before exploring further.
Create a meter
A meter defines the unit of measurement — what event name to listen for and how to aggregate the raw events into a billable quantity.The
For API call billing,
event_name links the meter to events you send later — any event with event_name: "api_call" is captured by this meter. The aggregate_type controls how Borga combines individual events into a single quantity for the billing period:| Aggregate type | Behaviour |
|---|---|
count | Number of events received. |
sum | Sum of the value field across all events. |
max | Highest value seen across all events. |
min | Lowest value seen across all events. |
avg | Average value across all events. |
unique | Count of distinct value entries (deduplication). |
count is the right choice. For data transfer billing, use sum and pass bytes in the value field.Create a metered price
Create a price that references the meter. Set The
recurring.usage_type to "metered" so Borga knows to aggregate events rather than charge a fixed amount.unit_amount is the price per unit in whole ISK. In this example, each API call costs 1 kr. You can combine a metered price with a fixed base price by including both as items on the same subscription.Create a subscription with the metered price
Create a subscription that includes the metered price as one of its items. The customer is not charged for usage until Borga invoices at the end of the billing period.You can add both a fixed base price and the metered price to the same subscription to implement a “base fee plus usage” model:
curl
Ingest usage events
Send usage events from your application as they occur. Each event must include the Use the batch endpoint (
event_name that matches your meter and the customer being charged.POST /v1/events/batch) when you need to ingest high volumes of events. Batching reduces API call overhead and is the recommended approach for ingesting events asynchronously from a queue.Check quantities
At any point during the billing period, query the aggregated quantity for a customer to see how much usage they have accumulated.The response includes the aggregated
quantity for the given customer and time range. Use this to build usage dashboards or to preview what a customer will be charged at the end of the period.Displaying usage to customers
You can expose usage data directly to your customers by queryingGET /v1/meters/{id}/quantities from your server and surfacing the result in your application UI. This helps customers understand their consumption before the invoice arrives and reduces billing-related support requests.
Next steps
- Subscriptions — set up fixed recurring plans alongside or instead of metered pricing
- Webhooks — receive
invoice.paidevents when usage invoices are collected - Accounting link — sync invoices generated from metered usage to your accounting software