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 subscriptions, calculates charges, issues invoices, and collects payments today.
- The customer, subscription, 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 subscription IDs to Lago and add server-side event delivery through a Lago SDK or REST API.
- 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. Both matter for duplicate protection on ClickHouse-based event pipelines.
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. SetLAGO_API_KEY in your terminal or secret manager without putting it in a prompt or source control. Install the CLI where you run your agent:
--api-url is the API service’s base URL, without /api/v1. 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 existing metrics and plans before proposing changes:
[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 usage charge from saved app records, then read Lago’s current usage for that subscription:- Quantity and usage charge 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 charge should not increase. - For the full bill, add any base fee, credits, and taxes. With Premium, preview the invoice and compare each line and the total. Invoice preview also requires Premium on self-hosted Lago.
[customer ID], [subscription ID], and [source record ID] with IDs from the same isolated test organization:
If the result differs
Prompt. Replace
[customer ID], [billing period], [expected amount], and [observed amount] with the values you are investigating: