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

# Contracts

> Create Contracts, override their rate cards and phases, read current usage, and end them with lago v2 contracts.

| Command | Description |
| - | - |
| `v2 contracts create` | Create a Contract for an existing customer, with or without a plan. |
| `v2 contracts get <external_id>` | Retrieve the live pending or active Contract. `--status` selects a terminated or canceled one. |
| `v2 contracts list` | List Contracts. Filters: `--external-customer-id`, `--external-id`, `--plan-code`, `--status`, `--has-rate-overrides`, `--billing-entity-ids`, `--search-term`. |
| `v2 contracts update <external_id>` | Partial update. Also `patch`. Allowed fields depend on the status. |
| `v2 contracts current-usage <external_id>` | Usage across the open billing windows of the active Contract. |
| `v2 contracts delete <external_id>` | End the lifecycle: terminate an active Contract, cancel a pending one. Confirmation-gated. |
| `v2 contract-applied-rate-cards create\|list <contract_external_id>` | Attach a rate card to a pending Contract, or list its applied rate cards. |
| `v2 contract-applied-rate-cards get\|update\|delete <contract_external_id> <code>` | One applied rate card, addressed by its rate card code. `delete` is confirmation-gated. |
| `v2 contract-rate-phases create\|list <contract_external_id> <applied_rate_card_code>` | Insert a phase, or list phases in position order. |
| `v2 contract-rate-phases update\|delete <contract_external_id> <applied_rate_card_code> <code>` | Override a phase's pricing, or remove a phase. `delete` is confirmation-gated. |

## create

| Field | Description |
| - | - |
| `external_id`, `external_customer_id` | Required. One pending or active Contract may use an `external_id` at a time. |
| `code` | Required by the API. Unique for the `external_id`, including ended Contracts. Pass it with `--input`: CLI v1.3.0 has no flag for it. |
| `plan_code` | Optional. The plan supplies the initial applied rate cards. A plan-less Contract uses rate cards attached directly. |
| `started_at` | Defaults to now, which creates an active Contract. A future start creates a pending one. |
| `billing_anchor_date`, `ended_at` | Optional. `ended_at` must be after the start and not in the past. |
| `name`, `consolidate_invoice`, `purchase_order_number`, `invoice_custom_section` | Optional. |

Because `code` has no flag, create Contracts with `--input` and the full `{"contract": {...}}` body. `--input` ignores the other body flags. CLI v1.3.0 also lists a `--billing-time` flag from its pinned spec. The API no longer accepts `billing_time` on Contracts, so leave it out.

## Overrides

Only pending Contracts accept changes to applied rate cards and phases. An active Contract's pricing is fixed. Override pricing per Contract with `--rate-override` on its rate phases: `rate_model`, `rate_properties` and optionally the billing interval. Structural fields such as `currency`, `billing_timing` and `proration` are not overridable. On update, `--rate-override null` removes the override.

## Current usage

`current-usage` returns `current_usage` with totals and one entry per rate card: `units`, `events_count`, `amount_cents`, the rate phase and the billing window. Filter by `--rate-card-code`, `--product-code`, `--product-filter-code` or `--product-type`. `--apply-taxes false` leaves taxes out. A pending Contract has no usage. Totals can span several future invoices.

## Endpoints newer than CLI v1.3.0

The live API has endpoints that CLI v1.3.0 does not generate. Reach them with [`lago api`](https://getlago.com/docs/v2/guide/lago-cli/commands/helpers):

* Retrieve a specific Contract by code, including after it ends: `GET /api/v2/contracts/{external_id}?contract_code={code}`.
* Draft Contracts and `POST /api/v2/contracts/{external_id}/publish`.
* Contract alerts under `/api/v2/contracts/{external_id}/alerts`.

See [Contracts](https://getlago.com/docs/v2/guide/contracts/overview.md), [lifecycle](https://getlago.com/docs/v2/guide/contracts/lifecycle.md), [overrides](https://getlago.com/docs/v2/guide/contracts/overrides.md) and [end or cancel](https://getlago.com/docs/v2/guide/contracts/end-or-cancel.md).

```bash create theme={"dark"}
lago v2 contracts create --input '{
  "contract": {
    "external_id": "acme_main",
    "code": "acme_main_2027",
    "name": "Acme main",
    "external_customer_id": "acme",
    "plan_code": "api_monthly",
    "started_at": "2027-01-01T00:00:00Z",
    "billing_anchor_date": "2027-02-01"
  }
}'
```

```bash read theme={"dark"}
lago v2 contracts get acme_main --expands applied_rate_cards,plan
lago v2 contracts list --external-customer-id acme --status active,pending
lago api GET '/api/v2/contracts/acme_main?contract_code=acme_main_2027'
```

```bash override a phase theme={"dark"}
# Pending Contracts only
lago v2 contract-rate-phases list acme_main monthly_service_usd
lago v2 contract-rate-phases update acme_main monthly_service_usd introductory \
  --rate-override '{"rate_model":"standard","rate_properties":{"amount":"40"}}'
```

```bash attach a rate card theme={"dark"}
lago v2 contract-applied-rate-cards create acme_main \
  --rate-card-code support_usd --units 1
```

```bash current-usage theme={"dark"}
lago v2 contracts current-usage acme_main
lago v2 contracts current-usage acme_main --rate-card-code api_calls_usd --output json
```

```bash end theme={"dark"}
lago v2 contracts delete acme_main --confirm acme_main
lago v2 contracts get acme_main --status terminated
```

```text create theme={"dark"}
LAGO_ID      1a901a90-1a90-1a90-1a90-1a901a901a90
EXTERNAL_ID  acme_main
NAME         Acme main
STATUS       pending
```

```text current-usage theme={"dark"}
AMOUNT_CENTS          12000
CURRENCY              USD
EXTERNAL_CONTRACT_ID  acme_main
EXTERNAL_CUSTOMER_ID  acme
RATE_CARDS            2 items
TAXES_AMOUNT_CENTS    0
TOTAL_AMOUNT_CENTS    12000
```

```json current-usage --output json theme={"dark"}
{
  "current_usage": {
    "amount_cents": 2000,
    "currency": "USD",
    "external_contract_id": "acme_main",
    "external_customer_id": "acme",
    "rate_cards": [
      {
        "amount_cents": 2000,
        "billable_metric_code": "api_calls",
        "billing_timing": "arrears",
        "events_count": 2000,
        "from_datetime": "2027-01-01T00:00:00Z",
        "product_code": "api_calls_product",
        "product_type": "metered",
        "rate_card_code": "api_calls_usd",
        "rate_model": "standard",
        "rate_source": "rate",
        "to_datetime": "2027-01-31T23:59:59Z",
        "units": "2000"
      }
    ],
    "taxes_amount_cents": 0,
    "total_amount_cents": 2000
  }
}
```


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