> ## 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.

# Billable metrics

> Define what you meter with lago v2 billable-metrics: aggregation, field, filters, expressions.

| Command | Description |
| - | - |
| `v2 billable-metrics create` | Create a metric. |
| `v2 billable-metrics get <code>` | Retrieve a metric. |
| `v2 billable-metrics list` | List metrics, newest first. |
| `v2 billable-metrics update <code>` | Partial update. `patch` is the same operation sent as `PATCH`. |
| `v2 billable-metrics delete <code>` | Soft-delete a metric. Confirmation-gated. |

## create

| Flag | Description |
| - | - |
| `--name`, `--code` | Display name and the code events reference. Required. |
| `--aggregation-type` | `count_agg`, `sum_agg`, `max_agg`, `unique_count_agg`, `weighted_sum_agg`, `latest_agg`. Required. |
| `--field-name` | Event property to aggregate. Required for every type except `count_agg`. |
| `--recurring true` | Carry values across billing periods. |
| `--filters` | JSON array of `{"key","values"}` dimensions. [Product filters](https://getlago.com/docs/v2/guide/lago-cli/commands/product-catalog.md) select from these values. |
| `--expression` | Compute the value from event properties before aggregation. |
| `--rounding-function`, `--rounding-precision` | Round aggregated values. `round`, `ceil` or `floor`. |
| `--weighted-interval seconds` | Required for `weighted_sum_agg`. |

## update and delete

Once a metric is attached to a plan, only `name`, `description` and permitted filter changes are accepted. Locked fields return 422, exit 5. Filter values referenced by product filters cannot be removed.

`delete` soft-deletes the metric with its charges and alerts. A metric referenced by a product filter cannot be deleted.

See [billable metrics](https://getlago.com/docs/v2/guide/billable-metrics/create-billable-metrics.md) for aggregation behavior.

```bash create theme={"dark"}
# Count every event
lago v2 billable-metrics create --name "API calls" --code api_calls \
  --aggregation-type count_agg --recurring false

# Sum a property, with a filter dimension
lago v2 billable-metrics create --name Tokens --code llm_tokens \
  --aggregation-type sum_agg --field-name tokens \
  --filters '[{"key":"model","values":["small","large"]}]'
```

```bash get theme={"dark"}
lago v2 billable-metrics get api_calls
lago v2 billable-metrics get api_calls --query 'billable_metric.aggregation_type'

# Filters are returned only when expanded
lago v2 billable-metrics get llm_tokens --expands filters --query 'billable_metric.filters[].key'
```

```bash list theme={"dark"}
lago v2 billable-metrics list --limit 20
lago v2 billable-metrics list --all --output json | jq -r '.billable_metrics[].code'
```

```bash update theme={"dark"}
lago v2 billable-metrics update api_calls --name "API requests"
```

```bash delete theme={"dark"}
lago v2 billable-metrics delete api_calls --confirm api_calls
```

```text create theme={"dark"}
LAGO_ID  1a901a90-1a90-1a90-1a90-1a901a901a90
CODE     api_calls
NAME     API calls
```

```json get theme={"dark"}
{
  "billable_metric": {
    "aggregation_type": "count_agg",
    "code": "api_calls",
    "created_at": "2026-12-01T09:30:00Z",
    "deleted_at": null,
    "description": null,
    "expression": null,
    "field_name": null,
    "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
    "name": "API calls",
    "recurring": false,
    "rounding_function": null,
    "rounding_precision": null,
    "updated_at": "2026-12-01T09:30:00Z",
    "weighted_interval": null
  }
}
```

```text delete (no --confirm) theme={"dark"}
Error: confirmation required for api_calls
Suggestion: Pass --confirm "api_calls" or rerun in an interactive terminal.
```


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