Skip to main content
Follow this API walkthrough to configure a $100 monthly fee plus $0.01 per API call. You’ll create the pricing, apply a Plan to a customer through a Contract, and send usage events. For one full billing month with 2,000 calls, the expected fees total $120 USD before tax, with no discounts or credits.

Before you start

You need an API key with write access to the objects below and the Product catalog enabled on your organization. All requests use https://api.getlago.com/api/v2 (US). For the EU cluster, use https://api.eu.getlago.com/api/v2.
This example covers January 1–February 1, 2027, with usage dated January 15. Both Rate Cards bill after the billing period ends. Creating the Contract does not immediately generate the invoice shown at the end of this guide. The Contract starts on 2027-01-01T00:00:00Z and its first billing cycle ends on 2027-02-01. A Rate’s effective_from cannot be before today in your organization timezone. If you run this later, move the Rate and Contract dates forward together and update the Unix timestamp in both event examples. A different start can make the first cycle shorter than a month, and the first invoice can then differ from $120.

What you will build

1

Create the billable metric

Create a billable metric that counts API call events. Count (count_agg) does not need a field_name. With recurring: false, the aggregation resets at the end of each billing cycle.
Reference: Create a billable metric.
2

Create the Product category and Products

The category is optional. It groups both Products on usage and invoices. The fixed Product has no metric. The metered Product must reference one.Run all three requests below: create the Product category, then the monthly service Product and API calls Product.
References: Create a Product category, Create a Product.
3

Create the Rate Cards and Rates

Create a Rate Card for each Product. Both use USD and bill in arrears, meaning after the billing period ends. Proration is disabled, so fees are not adjusted for part of a billing period.Run both requests to create a Rate Card and its first Rate for each Product. Include the first Rate in rates to define its price and monthly billing interval. If the Rate is invalid, the whole request rolls back.
Check the result with GET /api/v2/rate_cards/api_calls_usd?expands[]=rates. References: Create a Rate Card, Rates.
4

Create the Plan

Create a USD Plan to combine the monthly service and API usage pricing.
Reference: Create a Plan.
5

Apply Rate Cards to the Plan

Apply both Rate Cards to the Plan. Set units to 1 for the monthly service. The API calls Product uses the quantity measured by the billable metric.
Apply the Rate Cards before any Contract uses the Plan: a Plan attached to a Contract is locked.
Run both requests below.
Without rate_phases, each applied Rate Card gets one indefinite phase that follows the active Rate.
Reference: Create a Plan applied Rate Card.
6

Create the customer

Create the customer who will receive the invoices. Use customer_example to identify this customer when creating the Contract.
Reference: Create a customer.
7

Create the Contract

The Contract applies api_monthly to customer_example. Set the required contract_code to identify this specific Contract, including when retrieving it after it ends. A future started_at creates a pending Contract. It becomes active at the start. billing_anchor_date sets when the first billing cycle ends.
Retrieve it with GET /api/v2/contracts/contract_example?contract_code=contract_example_2027&expands[]=applied_rate_cards to confirm the Plan, status, start and anchor. Reference: Create a Contract.
8

Send usage events

Send one event per API call, addressed to the Contract with external_contract_id. Each event needs a unique transaction_id. timestamp is in Unix seconds. 1800007200 is 2027-01-15T10:00:00Z.For this walkthrough, run the batch example to send all 2,000 events. The single-event request shows the payload format; you do not need to run it separately.
A batch holds at most 100 events by default. When you retry a request, keep the same transaction_id values. Deployments can limit how far a timestamp may sit from the request time. References: Ingest an event, Ingest a batch of events, Usage ingestion.
9

Check current usage

Current usage covers the Contract’s open billing windows. It is not a preview of one invoice.
After all 2,000 events are processed, expect a response like this (abridged):
Amounts ending in _cents are minor units: 12000 is $120.00. Newly accepted events can take a moment to appear. Reference: Retrieve Contract current usage.
10

Check the invoice

Both Rate Cards bill in arrears. When the first cycle ends on February 1, 2027, Lago bills the January period. List the customer’s invoices, then retrieve one with its fees.From the invoice list, select the invoice for this Contract and billing period. Replace __LAGO_INVOICE_ID__ with its Lago invoice ID.
Expected invoice lines, before tax:Each fee carries product_code, rate_card_code, rate_code, external_contract_id, units, from_datetime and to_datetime, so you can trace it back to the pricing that produced it. Taxes, if any, appear in taxes_amount_cents. References: List invoices, Retrieve an invoice, List fees.
An invoice records what the customer owes. It does not mean the customer has paid. Check payment_status separately from status.

Product catalog

Structure Products with categories and filters.

Pricing models

Graduated, volume, package, percentage and more.

Contracts

Start dates, anchors, phases and overrides.

API reference

Every endpoint, with request and response schemas.