Skip to content

Command reference

Every legion command grouped by task, with a link to the full flags of each.

On this page

Every command has --help with examples. The full reference on GitHub (opens in a new tab) lists every flag. Nouns are singular, with plural aliases, so legion rentals list works.

All commands accept the global flags -o, -p, -q, -y, --api-url, --no-color, --timeout and --debug. See Scripting and automation.

Getting started

Getting started
CommandWhat it does
legion auth loginSigns you in through the browser and saves an API key. logout removes it, and status shows who you are.
legion whoamiShows the user and organization you are logged in as.
legion offer listLists hosts with free GPUs, cheapest first. Filter by GPU model, count, price, country or region.
legion offer getShows one offer.
legion catalog listLists the starter images and premade models. get shows one.
legion ssh <rental>Connects to a rental. A shortcut for legion rental ssh.

Rentals

Rentals
CommandWhat it does
legion rental createRents GPUs and starts a container, after a preview. --env NAME=value and --secret-env NAME (repeatable) set environment variables, --setting key=value a premade model's settings, and --command and --arg the command of your own image. See Configuration.
legion rental list / getLists your rentals or shows one.
legion rental stop / startStops a rental and keeps its workspace, or starts it again.
legion rental deleteDeletes a rental and destroys its workspace.
legion rental waitWaits until a rental is running or stopped.
legion rental ssh / ssh-configConnects, or prints an ~/.ssh/config block so ssh, scp and rsync work.
legion rental chargesShows what one rental has cost.
legion rental serveShows the Service URL and service key of a premade model rental.
legion rental backup ...Estimates, creates, lists, gets, cancels and deletes backups, and makes download links.
legion rental export ...Creates, lists, gets and cancels workspace exports.

Services

A service is a public URL for something you run on Legion: a port on one of your rentals, or a model that Legion runs on rented GPUs and scales with traffic. One command group does everything, including exposing a port: legion services, shortened to legion svc. There is no separate legion ports. Commands that create, resume or change spend, and the ones that delete or revoke, ask first, and need --yes in a script.

Services
CommandWhat it does
legion services listLists your services with their mode, scaling, status and Service URL. --rental NAME filters; -o wide adds ids and spend.
legion services getShows one service: Service URL, access, status, hardware, replicas and spend.
legion services createCreates a service. On a rental: --rental NAME --port 8080 --access keys, with --access public (the default for a port) or keys (the default for a model) and --source CIDR to limit callers. Autoscaled: --catalog or --image --port, optional --gpu MODEL (repeatable, an allow-list: by default Legion picks the cheapest hardware that fits), optional --max-price (total per replica-hour), --monthly-cap (required) and --ack-host-visibility; for your own image --min-gpu-memory and --gpu-counts. It shows the likely hardware and the cost, then asks.
legion services updateChanges only what you name: --min, --max, --scale-to-zero, --target-concurrency, --gpu (the allow-list), --max-price, --monthly-cap, --spot, --placement, --access public\|keys, --source, or the model with --catalog or --image. --revision refuses the change if the service was edited meanwhile.
legion services autoscale onTurns a service on a rental into an autoscaled one. --monthly-cap is required; --keep-rental (the default) or --replace says what happens to the rental.
legion services autoscale offBack to one rental: --keep-replica NAME is the replica to keep.
legion services pause / resumeStops serving and bills no GPU time, or starts again.
legion services deleteDeletes a service and its keys. For a service on a rental the rental is untouched. On a terminal you type its name. Deleting an autoscaled service needs a fresh sign-in, which only a browser session gives.
legion services replicasLists the replicas, live and warm. --all adds those retired in the last 7 days.
legion services usageShows usage per day and this month's spend against the cap. --days sets the range and --window 1h\|24h\|7d the traffic window of the request points in -o json.
legion services eventsShows scaling steps, changes and key activity. --limit sets how many.
legion services keys listLists service keys with prefix, status, expiry and last use. A key marked legacy is a direct key from before services.
legion services keys createMakes a service key, shown once. --name, --expires 7d\|30d\|90d\|365d\|never, --rate-limit. -o name prints only the secret.
legion services keys rotateMakes a new key and keeps the old one for --overlap-hours (24 by default).
legion services keys revokeRevokes a key now.

legion services create and legion services update also take --env NAME=value, --secret-env NAME, --setting key=value, --command and --arg for an autoscaled service. A secret's value comes from standard input or a hidden prompt, never from an argument, and changing them rolls the replicas. See Configuration.

The same service keys serve every service, whatever its mode, and are managed with legion services keys.

Registry credentials

Registry credentials
CommandWhat it does
legion registry addSaves a username and a read-only token for the registry of --image, after checking they can read it. --name names it, --path-prefix sets which images use it.
legion registry listLists your organization's credentials: name, host, prefix, username, last used. Never a token.
legion registry replace <id>Replaces a credential's token (--image, --token-stdin, optionally --username), or renames it (--name).
legion registry remove <id>Removes a credential, after confirming. Refused while rentals still use it, and it names them.

The token is read from a hidden prompt or from standard input with --token-stdin. It is never a flag, so it stays out of your shell history:

Text
echo "$TOKEN" | legion registry add --image ghcr.io/acme/model:v3 --username acme-bot --token-stdin

Adding, replacing and removing need the registry.manage permission, which owners have. legion rental create --registry-credential <id> uses a credential other than the one matched to the image. See Private images.

Account

Account
CommandWhat it does
legion billing balanceShows your prepaid balance.
legion billing charges / activity / ledgerShows charges per rental, usage sessions, and balance changes.
legion ssh-key list / add / removeManages the SSH public keys you rent with.
legion api-key list / create / revokeManages API keys.

Settings and tools

Settings and tools
CommandWhat it does
legion profile list / create / use / deleteManages named profiles.
legion config get / setReads or changes a setting of the current profile.
legion completion bash\|zsh\|fish\|powershellPrints a shell completion script.
legion versionPrints the version.
legion help environment / exit-codesExplains settings and exit codes.