Skip to content

Idempotency

Retry requests that create rentals or move money safely, with an Idempotency-Key.

On this page

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:

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.

Shell
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_terminal defaults to true and ssh_agent_forwarding to false. See createRental.