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.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 (Reference: Create a billable metric.
count_agg) does not need a field_name. With recurring: false, the aggregation resets at the end of each billing cycle.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 Check the result with
rates to define its price and monthly billing interval. If the Rate is invalid, the whole request rolls back.GET /api/v2/rate_cards/api_calls_usd?expands[]=rates. References: Create a Rate Card, Rates.4
Create the Plan
5
Apply Rate Cards to the Plan
Apply both Rate Cards to the Plan. Set Run both requests below.Reference: Create a Plan applied Rate Card.
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.
Without
rate_phases, each applied Rate Card gets one indefinite phase that follows the active Rate.6
Create the customer
Create the customer who will receive the invoices. Use Reference: Create a customer.
customer_example to identify this customer when creating the Contract.7
Create the Contract
The Contract applies Retrieve it with
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.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 A batch holds at most 100 events by default. When you retry a request, keep the same
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.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 Expected invoice lines, before tax:
__LAGO_INVOICE_ID__ with its Lago invoice ID.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.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.