The legion command line
Install the legion CLI, log in, and rent a GPU, SSH in and stop billing from your terminal.
After this page legion is installed and logged in, and you have rented a GPU, connected to it and stopped it, all from your terminal. The CLI uses the same API as the app, so everything you do shows up there too.
Install
On macOS and Linux:
curl -fsSL https://raw.githubusercontent.com/AmbientCrypto/legion-cli/main/scripts/install.sh | bashThe script picks the build for your system, checks its checksum and installs legion to ~/. Make sure that folder is on your PATH. Set LEGION_ to install elsewhere, or LEGION_ to pin a release. Run the same command again to upgrade.
On Windows, download the . from the releases page (opens in a new tab), unzip it and put legion. in a folder on your PATH.
Check it works:
legion versionLog in
legion auth loginThis opens Legion's sign-in page in your browser. Sign in, approve Legion CLI, and legion saves the API key the approval creates: scope full (Full access in the app), named Legion CLI (<this computer>), valid for 90 days. It is listed under Settings, then API keys, where you can revoke it. legion auth logout revokes it too. See Authentication for what keys are.
The browser must run on the same computer as legion, because the sign-in returns to a port on 127.. Add --no-browser to print the sign-in URL instead of opening a browser.
On a remote machine, use --paste. Create a key under Settings, then API keys, and paste it at the hidden prompt:
legion auth login --pasteTo check who you are logged in as, run legion whoami.
In CI, skip the sign-in. Pipe a key in, or set an environment variable:
echo "$LEGION_API_KEY" | legion auth login --with-tokenexport LEGION_API_KEY=YOUR_LEGION_API_KEYWith that set, you don't need to log in.
Quickstart
1. Find a GPU
legion offer list --gpu-model "RTX 4090" --max-price 2.50Offers are listed cheapest first, with prices per GPU-hour. Add -o wide for more columns. legion catalog list shows the starter images and premade models you can run.
2. Rent it
legion rental create --offer amber-falcon --catalog pytorch --gpus 2legion shows a preview first: host, GPUs, price per GPU-hour and per hour, your balance, image and SSH key. It asks you to confirm, then waits until the rental is running. Billing starts then.
--dry-runshows the preview and stops, so nothing is rented.--asyncreturns as soon as the rental is created.The price you saw is the most you will pay. If the host's price rises before you confirm, nothing is rented and legion tells you the new price. Use
--max-priceto allow more.
3. Connect
legion ssh quiet-river-7k2f
legion ssh quiet-river-7k2f -- nvidia-smiThe first opens a shell as root. The second runs one command and returns. A rental is named by its id, its friendly name or any unique prefix. On a terminal you can leave the name out to pick from a list.
4. Stop it
legion rental stop quiet-river-7k2fThis ends GPU billing and keeps your workspace. Stored files are billed per GiB until you delete the rental. See Stopping, backups and how long your data is kept.
5. Delete it
legion rental delete quiet-river-7k2fThis destroys the workspace for good, so back up first if you need the files: legion rental backup create. On a terminal you type the rental's name to confirm.
Shell completion
Completion suggests commands and flags, and also your live rental names, host names, catalog ids, saved SSH key labels and GPU models.
bash, in ~/:
source <(legion completion bash)zsh. Write the script to a folder on your fpath, then restart the shell. If completion isn't on yet, enable it first:
echo "autoload -U compinit; compinit" >> ~/.zshrc
legion completion zsh > "${fpath[1]}/_legion"fish:
legion completion fish > ~/.config/fish/completions/legion.fishNext steps
Scripting and automation: output formats, exit codes, environment variables and profiles.
Command reference: every command, with a link to its full flags.