# Create workspace export download link

> POST /v1/rentals/{rental_id}/workspace-exports/{export_id}/download-links. Charges the download and answers a link: 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-workspace-export-download-link

`POST https://api.legion.ambient.xyz/v1/rentals/{rental_id}/workspace-exports/{export_id}/download-links`

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

Charges the download and answers a link: `url` is a Legion address (`/v1/downloads/<token>`) that works
once, until `expires_at` (`download_link_ttl_seconds`). The first request to it answers 302 to the file, which
stays valid for 5 minutes (a download that has started keeps going); a second request, or one after
`expires_at`, is 410. The link is a bearer secret: do not log or share it. Every link is charged, never
refunded: `charge_cents` = the file's size in GiB times `export_cents_per_gib` (`getStoragePolicy`),
rounded up to a whole cent, at least 1 cent; 402 `insufficient_credit` without credit or when the balance
does not cover it. 409 `export_not_ready` unless the export is `ready`.

`Idempotency-Key` is required. 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` ("This download
link was already used or has expired. Make a new link."): make another with a new key. `number` is 1 for
the first link of the export, and so on. Requires `rentals.manage`.

## Path parameters

- `rental_id`, string (uuid), required
- `export_id`, string (uuid), required

## Headers

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

## Responses

### 201

The link.

- `url`, string, required: A Legion address that redirects to the file once. A bearer secret.
- `expires_at`, string (date-time), required
- `charge_cents`, integer (int64), required: What this link was charged, US cents: at least 1, 0 only while the operator has set the price to 0.
- `number`, integer, required: 1 for the first link of the export, and so on.

Example:

```json
{
  "url": "string",
  "expires_at": "2026-10-15T12:00:00Z",
  "charge_cents": 0,
  "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.

### 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 [`export_not_ready`](https://legion.ambient.xyz/docs/errors#export_not_ready)
- 410 [`link_used`](https://legion.ambient.xyz/docs/errors#link_used)
- 503 [`exports_unavailable`](https://legion.ambient.xyz/docs/errors#exports_unavailable)

## Example request

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