# Back up a stopped or failed rental's workspace

> POST /v1/rentals/{rental_id}/backups. Asks the host's agent to upload the rental's /workspace (only /workspace) as one tar file to Legion's backup storage, where it is kept retention_days (7…

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

`POST https://api.legion.ambient.xyz/v1/rentals/{rental_id}/backups`

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

Asks the host's agent to upload the rental's `/workspace` (only `/workspace`) as one tar file to Legion's
backup storage, where it is kept `retention_days` (7 by default, or 30) from when it is ready. Answers 202 with the backup, `queued`; poll `getBackup` (or the rental's
`latest_backup`) until it is `ready`, then download it with `createBackupDownloadLink`.

**Price.** The quote of `estimateRentalBackup` is charged when the backup is accepted (the organization
needs credit for it: 402 `insufficient_credit`); when it is ready the price is computed from the real
size and the difference is refunded; a backup that fails or is cancelled is refunded in full. The price
includes one download. All of it goes to Ambient.

**Unknown size.** When the host does not report the workspace's size (`estimate_basis` `disk_share`), the
quote is computed on the rental's whole disk share and is an upper bound: show it as "up to". The real
size trues it down. A backup larger than its quote is never charged more than the quote.

**Upload time.** The upload runs at the host's own upload speed and must finish within 12 hours of its
start (the agent cuts it then; it fails and is refunded). When the size is known and the host's measured
speed says it cannot finish in time, the request is refused with 409 `backup_too_slow` (the detail gives
the expected hours); `estimateRentalBackup` says so first (`fits_upload_window`). While it uploads,
`uploaded_bytes`, `upload_rate_bytes_per_second`, `estimated_completion_at` and `upload_deadline` show the progress.

**While it runs.** While a backup is `queued` or `uploading` its rental cannot be started (409
`backup_in_progress`) or deleted by its renter (409 `backup_in_progress`), its disk is never reclaimed, and
it is not deleted when its 72 hours are up: the deletion waits until the backup ends. A backup that has
not started uploading within 24 hours, or uploads for more than 12 hours, fails; these limits then
ends, the charge is refunded, and the rental keeps its own deadline (no extra time).

**Back up, then delete.** With `delete_rental_after` the rental is deleted (reason `renter_deleted`) as
soon as the backup is ready; if the backup fails or is cancelled nothing is deleted.

The rental must be `stopped` or `failed`, not held, its host online and its agent able to export (409
`rental_not_stopped`, `rental_held`, `host_offline`, `host_unsupported`); one backup or export at a time
per rental (409 `backup_in_progress`, `export_in_progress`); 6 backups and exports an hour per
organization (429 `rate_limited`). 503 `backups_unavailable` when Legion has no backup storage, and
`billing_unavailable` when it cannot read the balance to check the quote. `Idempotency-Key` is optional:
a retry with the same key and body returns the same backup. Requires `rentals.manage`.

## Path parameters

- `rental_id`, string (uuid), required

## Headers

- `Idempotency-Key`, string: Client-chosen key, unique per request intent, at most 255 characters.

## Request body

- `retention_days`, BackupRetentionDays: How many days a backup is kept once it is ready. 7 by default.
- `delete_rental_after`, boolean: "Back up, then delete": delete the rental (reason `renter_deleted`) as soon as the backup is ready. Nothing is deleted if the backup fails or is cancelled. Default false.

Example:

```json
{
  "retention_days": 7,
  "delete_rental_after": false
}
```

## Responses

### 202

The backup, queued.

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

### 402

The organization has no credit (`code` is `insufficient_credit`).

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

### 422

The Idempotency-Key was already used with a different request body.

### 429

Rate limited (`code` is `rate_limited`), or the organization asked the
pull-through mirror to copy in too many different tags or digests of one
repository today (`mirror_quota_exceeded`). Retry after the `Retry-After`
seconds.

### 500

An unexpected server error. Safe to retry.

### 503

A dependency is unavailable (`terminal_signing_unavailable`;
`image_registry_unavailable` when the image's registry did not answer in
time or failed; `secrets_unavailable` when secret variables cannot be
stored or read). Safe to retry.

## Errors

- 402 [`insufficient_credit`](https://legion.ambient.xyz/docs/errors#insufficient_credit)
- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 409 [`backup_in_progress`](https://legion.ambient.xyz/docs/errors#backup_in_progress)
- 409 [`backup_too_slow`](https://legion.ambient.xyz/docs/errors#backup_too_slow)
- 409 [`export_in_progress`](https://legion.ambient.xyz/docs/errors#export_in_progress)
- 409 [`host_offline`](https://legion.ambient.xyz/docs/errors#host_offline)
- 409 [`host_unsupported`](https://legion.ambient.xyz/docs/errors#host_unsupported)
- 409 [`rental_held`](https://legion.ambient.xyz/docs/errors#rental_held)
- 409 [`rental_not_stopped`](https://legion.ambient.xyz/docs/errors#rental_not_stopped)
- 409 [`rental_managed_by_service`](https://legion.ambient.xyz/docs/errors#rental_managed_by_service)
- 422 [`idempotency_key_reused`](https://legion.ambient.xyz/docs/errors#idempotency_key_reused)
- 429 [`rate_limited`](https://legion.ambient.xyz/docs/errors#rate_limited)
- 503 [`backups_unavailable`](https://legion.ambient.xyz/docs/errors#backups_unavailable)
- 503 [`billing_unavailable`](https://legion.ambient.xyz/docs/errors#billing_unavailable)

## Example request

```sh
curl -s -X POST "https://api.legion.ambient.xyz/v1/rentals/$RENTAL_ID/backups" \
  -H "Authorization: Bearer $LEGION_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "retention_days": 7,
  "delete_rental_after": false
}'
```
