# Mint a download link for a ready backup

> POST /v1/backups/{backup_id}/download-links. A single-use link to the backup's tar file: url is a Legion address (/v1/downloads/<token>) that works once, until expires_at (download_link_ttl_seconds…

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

`POST https://api.legion.ambient.xyz/v1/backups/{backup_id}/download-links`

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

A single-use link to the backup's tar file: `url` is a Legion address
(`/v1/downloads/<token>`) that works once, until `expires_at` (`download_link_ttl_seconds`, 1 hour by
default); its first use answers 302 to the file, a second use or one after `expires_at` is 410. A bearer
secret: do not log or share it. The backup's price includes one download: the first link is free (`charge` is zero);
every further link is charged the transfer of the file again (`charge`, $0.12 per GiB, charged at once
and never refunded; 402 `insufficient_credit` without credit). At most 5 links per backup per 24 hours
(429 `rate_limited`, with `Retry-After`). 409 `backup_not_ready` unless the backup is `ready`. `Idempotency-Key` is optional: a retry with the same key returns the same link and charges nothing more
while the link has not been used and has not expired; after that it is 410 `link_used` (make a new link
with another key). Requires `rentals.manage`.

## Path parameters

- `backup_id`, string (uuid), required

## Headers

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

## Responses

### 201

The link.

- `url`, string, required: A single-use Legion address (`/v1/downloads/<token>`) that redirects to the tar file once, valid until `expires_at`. A bearer secret.
- `expires_at`, string (date-time), required
- `charge`, Money, required: What this link was charged. Zero for the first link, which the backup's price includes.
- `link_number`, integer, required: 1 for the first link of the backup, and so on.

Example:

```json
{
  "url": "string",
  "expires_at": "2026-10-15T12:00:00Z",
  "charge": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "link_number": 1
}
```

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

### 410

The download link was already used or has expired (`code` is `link_used`). Make a new link.

### 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_not_ready`](https://legion.ambient.xyz/docs/errors#backup_not_ready)
- 410 [`link_used`](https://legion.ambient.xyz/docs/errors#link_used)
- 429 [`rate_limited`](https://legion.ambient.xyz/docs/errors#rate_limited)
- 503 [`backups_unavailable`](https://legion.ambient.xyz/docs/errors#backups_unavailable)

## Example request

```sh
curl -s -X POST "https://api.legion.ambient.xyz/v1/backups/$BACKUP_ID/download-links" \
  -H "Authorization: Bearer $LEGION_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```
