Idempotency
Retry requests that create rentals or move money safely, with an Idempotency-Key.
A network error can leave you unsure whether a request went through. With an Idempotency-Key, you can send it again without renting twice or paying twice.
Which operations take one
These operations require an Idempotency-Key header:
Rent GPUs on a host
POST /v1/ rentals Make a single-use download link for a ready workspace export
POST /v1/ rentals/ {rental_ id}/ workspace-exports/ {export_ id}/ download-links Back up a stopped or failed rental's workspace
POST /v1/ rentals/ {rental_ id}/ backups Mint a download link for a ready backup
POST /v1/ backups/ {backup_ id}/ download-links Create a service
POST /v1/ services Create a service key
POST /v1/ services/ {service_ id}/ keys Top up the organization's balance
POST /v1/ billing/ top-ups Turn auto top-up on or off and set its amounts
PUT /v1/ billing/ auto-top-up Refund unused credit to the cards and bank accounts it came from
POST /v1/ billing/ credit-refunds Redeem a promo code
POST /v1/ billing/ promo-codes/ redeem Ask for a destination to be added to the allow-list
POST /v1/ egress-requests Schedule maintenance on one or many hosts
POST /v1/ maintenance-windows
Stopping, starting and deleting a rental are idempotent by themselves, and take no key.
How it works
Choose a key for each thing you mean to do, such as a UUID. It can be up to 255 characters.
Send the same key and the same body again, and you get the original result. Nothing is done twice.
Send the same key with a different body, and you get
422 idempotency_.key_ reused Use a new key for a new request.
Example: rent a GPU
This request rents a GPU and spends credit.
curl -s -X POST "https://api.legion.ambient.xyz/v1/rentals" \
-H "Authorization: Bearer $LEGION_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2b8e-3d4a-4f5e-9b7c-2a1d0e8f9c3b" \
-d '{
"host_id": "8c0e2f4a-1b3d-4e5f-9a7b-6c5d4e3f2a1b",
"gpu_count": 1,
"image": "pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime",
"ssh_public_key": "ssh-ed25519 AAAA… you@laptop"
}'If the request times out, send exactly the same command again. If the rental was created, you get it back; if not, it's created now.
web_ defaults to true and ssh_ to false. See createRental.