Skip to main content
Test your integration end to end before you bill real customers. This page covers the test setup and the order of operations. For a complete API walkthrough with every payload and the expected amounts, see Your first invoice.

Set up a test environment

Each Lago organization is a single environment. Lago has no test mode and no separate test API keys. To test without touching production data, use a separate organization, for example “Company Staging” next to “Company Production”.
  • Replicate the same configuration in both organizations: billable metrics, Products, Rate Cards, Plans and webhook endpoints. Codes are scoped to an organization, so you can reuse the same codes in both.
  • Contracts require the Product catalog. Make sure it is enabled on both organizations.
  • Each organization has its own API keys. Point your test environment at the test organization’s key and keep keys out of source code.
  • Your organization lives in one region. Send requests to https://api.getlago.com/api/v2 (US) or https://api.eu.getlago.com/api/v2 (EU). See Lago Cloud.
Set a grace period on the test organization’s billing entity. Invoices then stay in draft, so you can add late usage, refresh them and inspect fees before they are finalized. The grace period requires a premium license.

Run the flow

The Contracts flow is: billable metric, Product, Rate Card and Rates, Plan with applied Rate Cards, customer, Contract, events, invoice.
1

Define a billable metric

The billable metric defines how Lago aggregates usage events. Fixed Products do not need one.
  1. Access the Billable metrics section in the side menu.
  2. Create a new billable metric.
  3. Enter its name, the code your events will send and its aggregation type.
  4. Save the billable metric.
Learn more in Create billable metrics. API: Create a billable metric.
2

Create the Products

A Product is what you sell. A metered Product references a billable metric. A fixed Product has no metric and bills a quantity set on the Plan or Contract.Create each Product with its Name, Code, Type (fixed or metered), its Billable metric for a metered Product, and an optional Product category.Learn more in Products. API: Create a Product.
3

Create the Rate Cards and Rates

A Rate Card sets the currency, billing timing and proration for one Product. Its Rates set the price, the pricing model, the billing interval and when the price takes effect.Create one Rate Card per Product and currency, with at least one Rate. A Rate’s effective_from cannot be before today in your organization timezone.Learn more in Rate Cards and Rates. API: Create a Rate Card.
4

Create the Plan and apply Rate Cards

  1. Open Plans and click Create plan.
  2. Enter the Plan’s Name, Code and Plan currency.
  3. Click Create plan.
  4. Open the Plan and select Rate cards under Overview.
  5. Open the Apply a rate card form, select the Product and its Rate Card, then click Add rate card. Repeat for each Product.
Apply every Rate Card before a Contract uses the Plan. A Plan attached to a Contract is locked.Learn more in Plans and Plan phases. API: Create a Plan, Apply a Rate Card to a Plan.
5

Create a customer

  1. Open Customers.
  2. Click Create a customer.
  3. Enter the customer’s name and external ID.
  4. Click Create customer.
Learn more in Customer management. API: Create a customer.
6

Create a Contract

The Contract applies the Plan to the customer and sets when billing starts.
  1. From the customer’s page or the Contract list, click Create contract.
  2. Check the Customer and select the Plan.
  3. Under Contract settings, click Add an external id and enter your Contract identifier.
  4. Enter the required Code.
  5. Set the start date and the Billing anchor date.
  6. Click Create contract.
A future start date creates a pending Contract that becomes active at the start. To test right away, set the start date to today. In the API, omit started_at to start the Contract now.Learn more in Contracts and Billing timeline. API: Create a Contract.
7

Send usage events

Your backend sends events to the Contract with external_contract_id, which matches the Contract’s external_id, not its contract_code. Each event needs a unique transaction_id. The code must match the billable metric code.
Send an event
timestamp is in Unix seconds and must fall inside the billing period you want to test. Keep the same transaction_id when you retry a request. Lago uses it for deduplication. To check what Lago received, open Developers and the Events tab.Learn more in Ingest usage. API: Ingest an event, Ingest a batch of events.
8

Check current usage

Current usage shows the provisional amounts for the Contract’s open billing windows, before any invoice exists. Use it to confirm that events reach the right Product and price.
Retrieve current usage
In the Dashboard, open the Contract and click the Usage tab. Newly accepted events can take a moment to appear.Learn more in Retrieve usage. API: Retrieve Contract current usage.
9

Receive webhooks

Lago notifies your application with webhooks, for example contract.started when a Contract starts and invoice.created when an invoice is finalized. With a grace period, invoice.drafted fires when the draft is created.
  1. Open Developers.
  2. Open the Webhooks tab.
  3. Click Add an endpoint.
  4. Enter a name and a public endpoint URL.
  5. Select Standard Webhooks as the signature and the events to receive.
  6. Click Create endpoint.
Verify the signature of every request in your test environment as you would in production. Learn more in Webhooks. API: Create a webhook endpoint.
10

Check the invoice

Lago generates invoices on the Contract’s billing timeline. Rate Cards billed in arrears are invoiced when the billing period ends. Rate Cards billed in advance are invoiced at the start of the period.With a grace period, the invoice is created as a draft. While it is a draft, you can:
  • Refresh it to include events sent after the period ended. API: PUT /api/v2/invoices/{lago_id}/refresh.
  • Finalize it to test the rest of your flow without waiting for the grace period to end. API: PUT /api/v2/invoices/{lago_id}/finalize. Finalization cannot be undone.
Inspect each fee’s product_code, rate_card_code, rate_code, external_contract_id, units, from_datetime and to_datetime to trace it back to your pricing.Learn more in Invoices and Fees. API: List invoices, Retrieve an invoice.

Test final billing

To test what happens when a customer leaves, end the Contract with DELETE /api/v2/contracts/{external_id}?contract_code={contract_code}. An active Contract becomes terminated and stops billing from that point, which can produce final fees. A pending Contract becomes canceled and never bills.
Ending a Contract is irreversible. Run this only on test Contracts. See End or cancel a Contract.

Limits of a test organization

  • Lago does not simulate time. Billing runs on real dates, so an arrears invoice for a monthly Rate appears when the real billing period ends. To see invoices sooner, use a daily Rate (billing_interval_unit: day) on a test Rate Card, set a near billing_anchor_date, or end the Contract.
  • An invoice records what the customer owes. It does not confirm payment. Check payment_status separately from status, and use your payment provider’s test mode in the test organization.