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

# End or cancel a Contract

> Cancel a pending Contract or end an active Contract, then review its status and billing records.

Cancel a pending Contract before it starts, or terminate an active Contract to end its billing timeline. Lago keeps the Contract record and billing history.

## Before you end a Contract

1. Retrieve the live Contract, save its `contract_code` and check its `status` and dates.
2. Decide between a scheduled end and an immediate end. They are not interchangeable:
   * A scheduled end is the Contract's `ended_at`. It must be after the start and not already in the past.
   * An immediate end is `DELETE /contracts/{external_id}`.
3. Check the open period in [current usage](https://getlago.com/docs/v2/guide/events/retrieve-usage.md#retrieve-current-usage) if the Contract is active.

## End the Contract immediately

`DELETE /contracts/{external_id}` ends the Contract lifecycle. It does not delete the record.

| Status before | Status after | Timestamp set |
| - | - | - |
| `pending` | `canceled` | `canceled_at` |
| `active` | `terminated` | `terminated_at` |

> [!WARNING]
>
> Ending a Contract is irreversible. A pending Contract becomes `canceled` and never starts billing. An active Contract becomes `terminated` and stops billing from that point, which can produce final fees. Review the Contract and its open usage before you send the request.

Your API key needs `contract` write permission. Pass the saved `contract_code` to select the Contract, especially when its `external_id` has been reused.

```bash End contract_example theme={"dark"}
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"

curl --location --request DELETE "$LAGO_URL/api/v2/contracts/contract_example?contract_code=contract_example_2027" \
  --header "Authorization: Bearer $API_KEY"
```

The response returns the Contract with its new `status`.

## Check final billing

After the Contract ends, check its status and review any fees and invoices for the closing billing period. The amounts depend on the billing configuration and the period being closed.

1. Retrieve the ended Contract with `GET /contracts/{external_id}?contract_code={contract_code}`, using the code you saved. Check that its status is `terminated` or `canceled`. This selects the same Contract even if its `external_id` has since been reused.
2. List the customer's [invoices](https://getlago.com/docs/v2/guide/invoicing/overview.md) and inspect their [fees](https://getlago.com/docs/v2/guide/invoicing/fees.md) and service periods.

Review invoices, [credit notes and refunds](https://getlago.com/docs/v2/guide/invoicing/credit-notes/overview.md) separately. Ending a Contract does not by itself confirm that money was collected or returned.

```bash Retrieve the terminated contract theme={"dark"}
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"

curl --location --request GET "$LAGO_URL/api/v2/contracts/contract_example?contract_code=contract_example_2027" \
  --header "Authorization: Bearer $API_KEY"
```

See [Contract lifecycle](https://getlago.com/docs/v2/guide/contracts/lifecycle.md#retrieve-a-specific-contract) for identifier reuse and historical Contracts.

> [card] [Contract lifecycle](https://getlago.com/docs/v2/guide/contracts/lifecycle.md)
>
> Statuses and transitions.

> [card] [Invoices](https://getlago.com/docs/v2/guide/invoicing/overview.md)
>
> Check what was billed.

> [card] [Delete a Contract (API)](https://getlago.com/docs/v2/api-reference/contracts/delete.md)
>
> `DELETE /contracts/{external_id}`

> [card] [Retrieve a Contract (API)](https://getlago.com/docs/v2/api-reference/contracts/retrieve.md)
>
> `GET /contracts/{external_id}`


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