# Cancel a queued or uploading backup

> POST /v1/backups/{backup_id}/cancel. Cancels a backup that is queued or uploading, as cancelWorkspaceExport cancels an export: it becomes cancelled, what was uploaded is discarded (the…

Source: https://legion.ambient.xyz/docs/api/rentals/cancel-backup

`POST https://api.legion.ambient.xyz/v1/backups/{backup_id}/cancel`

Authenticate with an API key: `Authorization: Bearer $LEGION_API_KEY`.

Cancels a backup that is `queued` or `uploading`, as `cancelWorkspaceExport` cancels an export: it becomes `cancelled`, what was uploaded is discarded (the upload is aborted, and aborted again
later in case a part landed), the host's agent stops on its next sync, its charge is refunded in full, and
its rental can be started or deleted again (a "back up, then delete" then deletes nothing). 409
`backup_not_cancellable` for one that is `ready` (delete it with `deleteBackup`), `failed`, `expired` or
`deleted`. Cancelling a cancelled backup succeeds. Requires `rentals.manage`.

## Path parameters

- `backup_id`, string (uuid), required

## Responses

### 200

The backup, `cancelled`.

- `id`, string (uuid), required
- `rental_id`, string (uuid), required
- `rental_name`, FriendlyName: A host's or rental's friendly name: a lowercase DNS label that starts with a letter and does not end with a hyphen. Unique across all hosts and rentals and never reused. A host's is generated as adjective-noun (`amber-falcon`) and can be changed by its owner; a rental's is generated as adjective-noun plus four base36 characters (`quiet-river-7k2f`) and never changes.
- `state`, BackupState, required: . `queued`: accepted, waiting for the rental to stop or for its host's agent to start uploading. `uploading`: the agent is uploading. `ready`: download it (`createBackupDownloadLink`) until `expires_at`. `failed`: see `error`; refunded in full. `cancelled`: cancelled before it was ready; refunded in full. `expired`: its retention ended. `deleted`: deleted early. An expired or deleted backup's file is purged 24 hours later.
- `retention_days`, BackupRetentionDays, required: How many days a backup is kept once it is ready. 7 by default.
- `requested_at`, string (date-time), required
- `upload_started_at`, string (date-time): When the agent started uploading.
- `ready_at`, string (date-time)
- `expires_at`, string (date-time): With `ready` and after, when it expires: `ready_at` plus `retention_days`.
- `ended_at`, string (date-time): When it failed, was cancelled, expired or was deleted.
- `purge_at`, string (date-time): For an `expired` or `deleted` backup, when its file is removed for good (24 hours on).
- `size_bytes`, integer (int64): The size of the tar file; with `ready`.
- `estimated_size_bytes`, integer (int64), required: The size the quote was computed on.
- `estimate_basis`, BackupEstimateBasis: . What a backup's quote was computed on. `disk_used`: the size the rental's host last reported its workspace uses (`disk_used_gib`). `disk_share`: the host does not report it (a host whose disk quota is not enforced, for example not on XFS), so the quote is the rental's whole disk share (`resources.disk_gib`): an upper bound, "up to" this price, trued down to the real size when the backup is ready. Either way the charge never exceeds the quote: a backup larger than its estimate (a stale `disk_used_gib`) is charged the quote, not more.
- `total_bytes`, integer (int64): The size of `/workspace` the host's agent measured before uploading ('s `total_bytes`, as on an export); absent until it says. `estimated_completion_at` is against it, else against a measured `estimated_size_bytes`.
- `uploaded_bytes`, integer (int64): Progress, as an export's: the bytes of the parts the agent finished uploading so far (the one in flight is not counted). With `uploading`; equal to `size_bytes` once `ready`.
- `upload_rate_bytes_per_second`, integer (int64): With `uploading`, once at least one part finished, the average upload speed so far.
- `estimated_completion_at`, string (date-time): With `uploading`, once at least one part finished: when the upload should finish at the speed it has had so far, against `estimated_size_bytes` (an upper bound with `disk_share`). An estimate, not a promise.
- `upload_deadline`, string (date-time): With `uploading`: when the backup fails if it has not finished, 12 hours after the upload started (the agent cuts the upload at the same time).
- `price`, BackupPrice, required: A backup's price, all of it Ambient's. `quoted` is what was charged when it was requested; `charged` is what it costs now, net of refunds: the quote until it is ready, then the price of its real size (never more than the quote), zero once it failed or was cancelled. `refunded` is what was given back. `storage` and `download` split the current price. Further download links are charged apart, on each link. All zero when backup charges are switched off.
  - `quoted`, Money, required
    - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
    - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
  - `charged`, Money, required
    - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
    - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
  - `refunded`, Money, required
    - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
    - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
  - `storage`, Money, required
    - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
    - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
  - `download`, Money, required
    - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
    - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `delete_rental_after`, boolean, required: Whether the rental is deleted once this backup is ready ("back up, then delete").
- `download_links`, integer, required: How many download links were minted. The first is included in the price.
- `error`, string: Why a `failed` backup failed, in words for the renter.
- `automatic`, boolean: . True for a backup Legion started by itself because the rental's `auto_backup` was on when Legion stopped it; absent for one a member asked for.
- `origin`, string: . Who asked for it: `member` (the renter), `automatic` (the rental's `auto_backup`) or `admin` (a Legion Legion's "back up and stop" or "back up, then delete"). Every backup is the renter's, at its price.

Example:

```json
{
  "id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "rental_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "rental_name": "quiet-river-7k2f",
  "state": "queued",
  "retention_days": 7,
  "requested_at": "2026-10-15T12:00:00Z",
  "upload_started_at": "2026-10-15T12:00:00Z",
  "ready_at": "2026-10-15T12:00:00Z",
  "expires_at": "2026-10-15T12:00:00Z",
  "ended_at": "2026-10-15T12:00:00Z",
  "purge_at": "2026-10-15T12:00:00Z",
  "size_bytes": 0,
  "estimated_size_bytes": 0,
  "estimate_basis": "disk_used",
  "total_bytes": 0,
  "uploaded_bytes": 0,
  "upload_rate_bytes_per_second": 0,
  "estimated_completion_at": "2026-10-15T12:00:00Z",
  "upload_deadline": "2026-10-15T12:00:00Z",
  "price": {
    "quoted": {
      "amount_minor": 250,
      "currency": "USD"
    },
    "charged": {
      "amount_minor": 250,
      "currency": "USD"
    },
    "refunded": {
      "amount_minor": 250,
      "currency": "USD"
    },
    "storage": {
      "amount_minor": 250,
      "currency": "USD"
    },
    "download": {
      "amount_minor": 250,
      "currency": "USD"
    }
  },
  "delete_rental_after": false,
  "download_links": 0,
  "error": "string",
  "automatic": false,
  "origin": "member"
}
```

### 400

The request is malformed or fails validation. An image reference that
is not a container image reference answers `invalid_image_reference`.

### 401

Missing, unknown, expired or revoked credentials.

### 403

The caller lacks the permission this operation requires (`forbidden`),
or signed in without having joined an organization yet
(`no_organization`; `getOnboarding` and the invitation and
organization operations under it work), or could not sign in
(`email_unverified`, `account_conflict`, and `domain_not_allowed`). `not_invited` is no longer returned to
session tokens.

`access_not_approved`: a signed-in person who is not approved
for the beta yet. Every operation that takes a credential answers it to
them, except `getMe` and `joinMyWaitlist`; the problem carries
`access` (`waitlisted` or `not_requested`, and the email). Approved
means a member of an organization, holding a pending invitation, or Legion; an API key always belongs to a member.

`oauth_token_mcp_only`: the caller sent an OAuth access token (`lgo_`), which is accepted
only by `mcpMessage` and the tool calls it dispatches. Every other operation answers it, whatever
the token's scope. Use an API key or the Legion web app.

`org_suspended`: the caller's organization is suspended. Every operation that takes a
credential answers it, by session or API key, except `getMe` (which shows `org.suspended_at` and
`org.suspension_reason`) and the support operations under `/v1/support/`.

`terms_not_accepted`: an approved caller who has not accepted
the current version of the Terms of Use and the Acceptable Use Policy. Every operation that takes a credential answers it, except `getMe`,
`acceptLegalDocuments`, `joinMyWaitlist` and the wind-down operations
(`listRentals`, `stopRental`, `deleteRental`, `listHosts`,
`updateListing` with `listed` false, `removeHost`); the problem
carries `legal`. An API key acts for the person who created it, so it
is refused until that person accepts. Terminal
operations also return
`session_required` (called with an API key) and `step_up_required`
(neither a sign-in nor a step-up challenge within the step-up window).

### 404

The resource does not exist or belongs to another organization.

### 409

The resource's current state does not allow the operation. `legal_versions_stale`: a legal document version sent is not the current one; the
problem's `legal` holds the current documents.

### 500

An unexpected server error. Safe to retry.

## Errors

- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 409 [`backup_not_cancellable`](https://legion.ambient.xyz/docs/errors#backup_not_cancellable)

## Example request

```sh
curl -s -X POST "https://api.legion.ambient.xyz/v1/backups/$BACKUP_ID/cancel" \
  -H "Authorization: Bearer $LEGION_API_KEY"
```
