Skip to main content
In this article, you will learn how to build a ‘pay-as-you-go’ billing system. This template is suitable for companies whose pricing fully depends on usage, such as cloud service providers and API companies, that only charge their customers for the resources they consume.

Pricing structure

For one of its products, Algolia Search, the platform offers its customers to subscribe for free and only pay based on usage. Although users don’t need to subscribe to access the platform, Algolia offers its customers discounts based on volume and commitment (rates available upon request).

Get started

1

Set up Lago

2

Create billable metrics

Create billable metrics to track request usage for Search and Recommend APIs.
  1. Set the aggregation_type to sum_agg to sum all request volumes
  2. Set the field_name to search_requests_volume for Search API tracking
  3. Set the recurring to false for metered billing
3

Create a plan

Create a plan to price packages of requests used.
  1. Set the amount_cents to 0 since there is no subscription fee
  2. Set the charges to use package pricing model with Algolia’s rates
  3. Configure free_units of 10,000 requests per month included
Refer to the API reference and guide on package charges to learn more.
4

Create a customer

Create a customer with a unique external_id.
Refer to the API reference to create a customer.
5

Create a subscription

Create a subscription for the customer with the plan’s code.
Refer to the API reference to create a subscription.
6

Ingest usage via events

Send usage events to Lago to track API requests.
  1. Set the code to match your billable metric code
  2. Include search_requests_volume property with the number of requests
Refer to the API reference to create an event.
7

Monitor current usage

Track real-time customer usage for the current billing period.
Refer to the API reference to get the current usage.

Wrap-up

‘Pay-as-you-go’ pricing strategies are popular among API companies like Algolia. With Lago, you can adapt this template to your products and services, using some of our most popular features:
  1. Plan models, with or without subscription;‍
  2. Billable metrics, including the ‘sum’ aggregation type; and‍
  3. Charges, including our package and graduated pricing models.
Give it a try, click here to get started!