API v2 is in beta. Endpoints return the
X-Lago-Endpoint-Status: beta header.lago v2. They are generated from the Lago API v2 document pinned in your CLI release and send requests to /api/v2 on your profile’s host. Use an SDK or the REST API in your application at runtime.
lago v2 requires CLI v1.1.0 or later. lago v2 apply requires v1.2.1 or later. Every v2 command requires the Product catalog to be enabled on your organization. API v2 is in beta: lago v2 command and flag names follow the v2 spec and can change with it, so pin a CLI version before scripting against them.Install
Homebrew on macOS and Linux installs the binary, the man page and the shell completions:lago version prints the CLI version and the two API specs it was built from: SPEC_VERSION for v1 and SPEC_V2_VERSION for v2. lago upgrade tells you whether a newer release exists and the command to install it.
Configure
Get an API key from Developers > API keys in the Lago app and confirm your region. For the walkthrough below, use a separate test organization or an isolated self-hosted instance. SetLAGO_API_KEY in your shell or secret manager without putting it in a prompt or source control, then:
init checks the key against the API before saving anything to ~/.config/lago/config.toml. Pass the base URL only. The profile stores the v1 base, and lago v2 commands swap /api/v1 for /api/v2 on the same host. One profile serves both APIs. The dashboard URL (app.getlago.com) is refused, because it is not the API.
lago whoami shows the profile, the organization timezone and the exact host requests go to. lago doctor checks configuration, network and authentication.
Verify your first usage charge
This walkthrough creates a billable metric, a metered Product, a Rate Card with one Rate, a Plan, a customer, a Contract and one event. The illustrative price is $1 per request, before taxes. Run it once in an isolated organization withjq installed. The cli_quickstart_* codes must be unused.
1. Check the connection and preview a request
2. Create the metric and the metered Product
3. Price it with a Rate Card
A Rate’seffective_from cannot be before today in your organization timezone. Set it to today’s date in that timezone, shown by lago whoami. The command below uses today’s UTC date.
amount is in currency units, so "1" means $1 per request. If the Rate is invalid, the whole request rolls back.
4. Create the Plan and apply the Rate Card
5. Create the customer and the Contract
code is required by the API, and CLI v1.3.0 has no --code flag for it yet. --input sends the complete request body, so it carries the contract wrapper. Without started_at, the Contract starts now and is active.
6. Send one event and check usage
Save the original timestamp. Reuse both it and the transaction ID if you retry this event.cli_quickstart_requests_usd entry in current_usage.rate_cards should show units: "1" (or an equivalent decimal) and amount_cents: 100: 1 request × $1 = $1. If usage is still zero, read it again after processing. Check the metric code, the Contract and the timestamp if it remains zero.
Retry only the lago v2 events send command above in the same shell, keeping the saved timestamp and transaction ID. Read current usage again: the quantity and amount should remain unchanged.
This verifies the usage charge, not taxes, payment collection or the full invoice lifecycle. Continue with your first invoice for the end-to-end billing cycle.
How it works
Flags are API fields
Asnake_case field is a --kebab-case flag. Nested fields carry their parent as a prefix. Objects and arrays take JSON. --input sends a whole request body, inline or from @file.json.
--input replaces every other body flag and is sent as written. Include the resource wrapper, such as {"rate_card": {...}}.
Creates print identifiers
Acreate or update prints the identifier block. Add --output json for the full resource.
Responses are wrapped
v2 responses are wrapped in the resource name, like v1. A--query starts with that wrapper. Lists put records under the plural name and pagination under meta.
Lists use cursors
v2 lists are cursor-paginated.--limit sets the page size. --after takes the previous response’s meta.next_cursor, and --before its meta.prev_cursor. --all follows the cursors until the last page. There is no --page on v2 lists.
Destructive operations ask first
Every v2delete, plus invoices void, invoices finalize, invoices retry-payment, invoices retry-taxes, credit-notes void and the credit note metadata deletes, prompts for the identifier. In a script, pass it with --confirm. lago v2 contracts delete ends the Contract: an active Contract is terminated, a draft or pending one is canceled.
Errors name the field
v2 validation errors carry a code per field. The CLI prints them asfield: code. In --output json, the error also carries error.field_errors with the raw {field, code, meta} entries. A v2 404 names the missing identifier.
Live is the default mode
--mode test is a safety declaration, not a sandbox. Live mode prints [LIVE] and gates destructive operations. Credentials passed by flag or environment run live unless you set a mode.
Scripting
Exit codes
Money is exact:
*_amount_cents are integers and units are decimal strings. The CLI sends no telemetry.
Command reference
One page per command group, with commands and their output side by side.
API reference
The v2 schemas the CLI is generated from.