Skip to main content
API v2 is in beta. Endpoints return the X-Lago-Endpoint-Status: beta header.
Use the Lago CLI to configure the Product catalog, create Contracts, send usage and read it back from your terminal or coding agent. It works with Lago Cloud US and EU, or self-hosted Lago. The v2 commands live under 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:
Anywhere Go 1.27 or later runs:
Release archives for macOS, Linux and Windows, with checksums signed by cosign, are on the releases page. 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.
If lago version prints a Docker Compose version, a shell alias named lago from a self-hosted Lago setup is shadowing the binary. Run unalias lago and remove the alias from your shell profile.

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. Set LAGO_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 with jq installed. The cli_quickstart_* codes must be unused.
--mode test labels the CLI profile. It does not create a sandbox or prevent writes. Creating a Contract starts billing it. Confirm the organization with lago whoami before proceeding.

1. Check the connection and preview a request

The dry run prints the method, URL, redacted headers and body without sending anything. The next steps make real writes to your selected organization.

2. Create the metric and the metered Product

3. Price it with a Rate Card

A Rate’s effective_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.
The Rate’s 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

Apply Rate Cards before a Contract uses the Plan. A Plan attached to a Contract is locked.

5. Create the customer and the Contract

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.
After event processing completes, the 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

A snake_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

A create 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 v2 delete, 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 as field: 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

Precedence is flags, then environment, then profile.

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.