> ## Documentation Index
> Fetch the complete documentation index at: https://getlago.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Catalog as code

> Keep the product catalog in YAML files under git and reconcile Lago with lago v2 apply.

`lago v2 apply DIR` makes the organization's product catalog match a folder of YAML files. The catalog can live in git and be reviewed like code. Requires CLI v1.2.1 or later.

| Command | Description |
| - | - |
| `lago v2 apply DIR` | Print the plan, then create and update in dependency order. |
| `lago v2 apply DIR --dry-run` | Print the plan and send nothing. |
| `lago v2 apply DIR --prune` | Also delete managed objects the files no longer declare. Confirmation-gated. |

## Files

`apply` reads every `.yml` and `.yaml` file under `DIR`. Split and nest them however you like. A file is a map whose keys are among:

| Key | Objects | Children |
| - | - | - |
| `billable_metrics` | [Billable metrics](https://getlago.com/docs/v2/guide/billable-metrics/create-billable-metrics.md) | |
| `product_categories` | [Product categories](https://getlago.com/docs/v2/guide/product-catalog/product-categories.md) | |
| `products` | [Products](https://getlago.com/docs/v2/guide/product-catalog/products) | |
| `rate_cards` | [Rate Cards](https://getlago.com/docs/v2/guide/rate-cards/overview.md) | `rates` |
| `plans` | [Plans](https://getlago.com/docs/v2/guide/plans/overview.md) | `applied_rate_cards` |

Each object takes the fields of its v2 create request and is matched by `code`. Numbers are sent as written and compared as decimals, so `"0.7"` and `0.70` match. Product filters, Contracts and customers are not managed by `apply`.

## How a run works

1. `apply` reads the files and the current catalog, then prints the plan: one row per object, with the action and the changed fields.
2. It refuses, before sending anything, a change the API cannot make in place. Examples: a product's `product_type`, the billing fields of a rate card that has rates, the frozen fields of an active or terminated rate, the currency of a plan with applied rate cards, or a billable metric a v1 plan charges. Rate dates are checked too, and applied rate card changes on a plan with a live Contract are refused.
3. It creates and updates in dependency order, sending only the fields that changed. A failed write stops the run. Rerunning picks up where it stopped.

## State and pruning

`apply` deletes nothing unless you pass `--prune`. It records the objects it manages in `DIR/.lago-state/<organization lago_id>.json`, or the path given by `--state`. Commit that file with the YAML. A run holds a `.lock` file next to the state while it writes.

`--prune` deletes the managed objects the files no longer declare. It never touches an object the folder did not create or adopt. When a declared plan lists `applied_rate_cards`, or a declared rate card lists `rates` (even an empty list), those children belong to the file, so `--prune` also removes the ones the file dropped. Without the key, they are left alone.

* **Rates are history.** Active and terminated rates are kept. To change a price, add a rate with a later `effective_from`. Only pending rates are pruned.
* **Plans are released, not deleted.** The v2 API has no plan delete. A dropped plan leaves the state and stays in Lago.
* **Cascades are refused.** `--prune` refuses, before any write, a delete that Lago would cascade to objects the run keeps: the products of a category, the rate cards and filters of a product, the v1 charges on a billable metric, or a rate card a plan still applies.

Deleting asks for confirmation. In scripts, pass `--confirm prune`.

> [!WARNING]
>
> `apply` writes to the organization of the active profile. Run `--dry-run` first, review the plan, and use `lago whoami` to confirm the organization before applying to live.

```yaml billing/catalog.yaml theme={"dark"}
billable_metrics:
  - code: api_calls
    name: API calls
    aggregation_type: count_agg
    recurring: false

products:
  - code: api_calls_product
    name: API calls
    product_type: metered
    billable_metric_code: api_calls

rate_cards:
  - code: api_calls_usd
    product_code: api_calls_product
    name: API calls USD
    currency: USD
    billing_timing: arrears
    rates:
      - code: api_calls_usd_2027_01
        effective_from: "2027-01-01T00:00:00Z"
        rate_model: standard
        rate_properties: { amount: "0.01" }
        billing_interval_unit: month
        billing_interval_count: 1

plans:
  - code: api_monthly
    name: API monthly
    currency: USD
    applied_rate_cards:
      - rate_card_code: api_calls_usd
```

```bash Plan and apply theme={"dark"}
lago v2 apply billing/ --dry-run
lago v2 apply billing/
```

```bash Prune theme={"dark"}
lago v2 apply billing/ --prune --dry-run
lago v2 apply billing/ --prune --confirm prune
```

```text Plan and apply theme={"dark"}
ACTION  KIND               CODE               PARENT       CHANGES  NOTE
create  billable metric    api_calls
create  product            api_calls_product
create  rate card          api_calls_usd                            with 1 rate(s)
create  plan               api_monthly
create  applied rate card  api_calls_usd      api_monthly
Plan: 5 to create, 0 to update, 0 to delete, 0 unchanged.
Dry run: no request was sent.
```

```text Plan locked by a Contract theme={"dark"}
Error: plan "api_monthly": its applied rate cards cannot change while contract(s) acme_main use it
Suggestion: Lago locks a plan with contracts: declare a new plan and migrate the contracts, or restore its applied rate cards in the files.
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.