lago v2 commands for terminal work and the v2 OpenAPI contract for exact schemas.
API v2 is in beta. Endpoints return the
X-Lago-Endpoint-Status: beta header.1. Map billing in your application
Tell your agent your pricing rules. Have it inspect the repository and identify:- Who pays, what action creates usage, and which saved record proves it happened.
- Which system owns contracts, calculates prices, issues invoices, and collects payments today.
- The customer, contract, and usage IDs that link that action to its bill.
- One example bill and any risk of charging a customer twice.
[pricing rules] with your billing period, currency, base fee, included usage, and overage rate:
2. Build and test locally
Once you agree on the billing plan, have your agent:- Map the app’s customer and contract IDs to a Lago customer
external_idand a Contractexternal_id. - Send usage server-side to
POST /api/v2/eventsorPOST /api/v2/events/batch, addressed withexternal_contract_id. v2 rejects the v1 identifier field with a422. - Test the example bill and a retry offline, without contacting Lago.
- Keep current billing in place unless you agreed to change it. Review the diff and tests before any live write.
transaction_id and timestamp. On the ClickHouse event store, the timestamp is part of the deduplication key, so a retry without it is billed again.
Prompt. Replace [approved billing plan] with the metric, billing period, price, and who will own invoices and payments:
3. Connect to the right Lago organization
First, get access to a Lago Cloud organization or self-hosted instance and its API key. The organization needs the product catalog enabled. SetLAGO_API_KEY in your terminal or secret manager without putting it in a prompt or source control. Install CLI 1.3.0 or later where you run your agent:
--api-url is the API service’s base URL, without /api/v1 or /api/v2. lago v2 commands send requests to /api/v2 on that host. Confirm the resolved organization and host before changing billing configuration:
--mode test is a CLI label, not a sandbox inside your organization. Use a separate test organization or an isolated self-hosted instance for live tests. Keep demo customers and plans out of shared production billing.
Inspect the existing catalog before proposing changes:
lago v2 apply. Each object takes the fields of its v2 create request and is matched by code. For example, a $100 monthly fee plus $0.01 per completed job:
billing/catalog.yml
effective_from dates. A Rate’s effective_from cannot be before today in your organization’s timezone. A fixed Product needs units on its applied Rate Card. Apply the Rate Cards to the Plan before any Contract uses it: a Plan attached to a Contract is locked. apply records the objects it manages in billing/.lago-state/. Commit that folder with the YAML. See the pricing models and Plans.
Before sending usage, identify or create the Lago customer and a Contract on that Plan. Use external IDs from your application. Review both requests as dry runs:
billing/contract.json wraps its fields in contract: external_id, contract_code, external_customer_id, plan_code, and optionally started_at and billing_anchor_date. A future started_at creates a pending Contract. Without it, the Contract starts now. Rate Cards with billing_timing: advance bill at the start of a period, so test this sequence in your isolated organization first.
Prompt. Replace [target organization] with the organization name and API host, and [approved pricing] with your reviewed price and metric:
4. Check what Lago recorded
Choose one customer and billing period. Calculate the expected usage quantity and amount from saved app records, then read Lago’s current usage for that Contract:rate_cards carries its rate_card_code, product_code, units and amount_cents. Add --rate-card-code or --product-code to narrow the result.
Check:
- Units and
amount_centsof the metered Rate Card against your calculation. If usage is zero, wait for processing and read again before investigating. - In an isolated test environment, retry one event with its original
transaction_idandtimestamp. The units should not increase. - For the full bill, check the fixed Rate Card entry and any taxes. When the period closes, compare each fee on the invoice with your calculation. v2 has no invoice preview.
[customer ID], [contract ID], and [source record ID] with IDs from the same isolated test organization:
If the result differs
Prompt. Replace
[contract ID], [billing period], [expected amount], and [observed amount] with the values you are investigating: