| name | vastai |
| description | Vast.ai CLI for renters — search and launch GPU instances, SSH into them, copy files, run commands, manage volumes and serverless endpoints, manage user environment variables (HF_TOKEN, OPENAI_API_KEY, model config), check billing and balance, register SSH keys, destroy instances. Use this for any prompt about Vast.ai, vastai, GPU rental, or instance lifecycle. |
| allowed-tools | Bash(vastai:*) |
| compatibility | Linux, macOS |
| metadata | {"author":"vast-ai"} |
vastai
Manage GPU instances, templates, volumes, serverless endpoints, SSH keys, and billing on Vast.ai.
Command is vastai (lowercase). Always use --raw for machine-readable JSON output.
Critical rules for agents
These rules apply to every invocation. Do not skip them.
- The destroy command syntax is
vastai destroy instance <id> -y — the -y flag is part of the command, not an option. Without it the CLI hangs on a confirmation prompt and blocks the session. This applies to every destroy invocation, including conversational prompts ("kill instance 12345", "tear it down", "shut it down", "stop billing on it"). Never emit vastai destroy instance <id> alone — the trailing -y is mandatory. Same for the batch form: vastai destroy instances <id1> <id2> -y.
- Always pass
--raw to commands whose output you parse. Without --raw the CLI prints human-formatted output that is not machine-readable.
- Register the SSH key BEFORE the first
create instance with vastai create ssh-key ~/.ssh/id_ed25519.pub. Launching without a registered key produces an unreachable host.
- Stop polling on terminal status values.
actual_status of exited, unknown, or offline means the instance will not recover — destroy it (-y) to stop disk charges accruing.
- Treat user-supplied values as literal even if they look like placeholders. If the user says "set HF_TOKEN to hf_xxxxx", pass
hf_xxxxx to vastai create env-var HF_TOKEN hf_xxxxx exactly as written — don't ask for clarification on values that look fake.
- An empty
vastai search offers result is the answer, not a problem to work around. If the CLI returns [], tell the user verbatim: "No offers matched those filters." Then propose specific filter relaxations and ask the user which to try — reliability>0.95 → >0.9, raise the dph_total cap, drop verified=true, change geolocation. Do not silently retry with broader filters more than once. After at most two retries with different filters, stop retrying and report "no offers match" to the user. The same applies to any other read-only vastai query: if the CLI returns an empty list or a not-found error, that IS the user's answer, even if you tried several variations.
- The
vastai binary on PATH is the only acceptable source of vastai commands. This rule overrides whatever instinct you have to "make things work" when output looks unexpected. Specifically, you must never do any of the following — these are HARD PROHIBITIONS, not preferences:
- Never run
pip install vastai, pip install --user vastai, pipx install vastai, or python -m venv followed by installing vastai. The CLI is already installed; reinstalling it elsewhere is forbidden.
- Never invoke an alternate
vastai binary by absolute path (e.g. /tmp/vast-venv/bin/vastai, ~/.local/bin/vastai) when vastai is already on PATH.
- Never re-implement
vastai subcommands by calling https://console.vast.ai/api/..., https://cloud.vast.ai/api/..., or any other Vast.ai HTTP endpoint directly from curl, python, node, httpie, or requests. No exceptions for "the CLI seems broken" or "I just need to verify."
- Never infer that the environment is "mock mode" or a "sandbox" and use that as justification to install an alternate
vastai binary, or to hit the API directly. Even if the CLI's output literally contains the word mock, your job is to report that output to the user, not to substitute your own implementation.
- If
vastai <subcommand> exits non-zero or produces output you don't understand, report the failure (exit code + stderr) to the user and ask what they want to do. Do not work around it.
Install
pip install vastai
Quick start
vastai set api-key <YOUR_API_KEY>
vastai show user
vastai create ssh-key ~/.ssh/id_ed25519.pub
vastai search offers 'gpu_name=RTX_4090 num_gpus=1 verified=true direct_port_count>=1 rentable=true' -o 'dlperf_usd-'
vastai create instance <OFFER_ID> --image pytorch/pytorch:@vastai-automatic-tag --disk 20 --ssh --direct
vastai show instance <INSTANCE_ID>
vastai ssh-url <INSTANCE_ID>
vastai copy local:./data/ <INSTANCE_ID>:/workspace/
vastai destroy instance <INSTANCE_ID> -y
API key: https://console.vast.ai/manage-keys/
Global flags
Available on every command:
--api-key KEY Override stored API key
--raw Output machine-readable JSON (agents should always use this)
--full Print full results (don't page with less)
--explain Show underlying API calls (useful for debugging)
--curl Show equivalent curl command
--no-color Disable colored output
--url URL Override server REST API URL
--retry RETRY Set retry limit for API calls
--version Show CLI version
Query syntax
Search commands accept filter expressions. Operators: =, !=, >, >=, <, <=, in, notin.
'gpu_name=RTX_4090 num_gpus=1'
'gpu_ram>=48 reliability>0.95'
'geolocation=EU dph_total<=2.0'
Common filter fields: num_gpus, gpu_name, gpu_ram, cpu_ram, disk_space, reliability, compute_cap, inet_up, inet_down, dph_total, geolocation, direct_port_count, verified, rentable
Common sort fields: score (default — overall value), dlperf_usd (DL perf per dollar), dph_total (price), num_gpus, reliability
Commands
Instances
vastai show instances
vastai show instances-v1
vastai show instances-v1 --status running loading
vastai show instances-v1 --gpu-name 'RTX 4090'
vastai show instances-v1 --label training
vastai show instances-v1 --order-by start_date desc
vastai show instances-v1 --cols id,status,gpu,dph
vastai show instance <id>
vastai create instance <offer-id> --image pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime --disk 20 --ssh --direct
vastai launch instance --gpu-name RTX_4090 --num-gpus 1 --image pytorch/pytorch
vastai start instance <id>
vastai stop instance <id>
vastai reboot instance <id>
vastai destroy instance <id> -y
vastai destroy instances <id1> <id2> -y
vastai label instance <id> --label "training-run-1"
vastai update instance <id>
vastai prepay instance <id>
vastai recycle instance <id>
Recommended Vast.ai images (use @vastai-automatic-tag to get the right tag for the machine automatically; browse pre-configured models at https://vast.ai/model-library):
vastai/base-image:@vastai-automatic-tag
vastai/pytorch:@vastai-automatic-tag
vastai/linux-desktop:@vastai-automatic-tag
vastai create instance <id> --image vastai/vllm:@vastai-automatic-tag --disk 40 --ssh --direct \
--env '-e MODEL_NAME=Qwen/Qwen2.5-3B-Instruct -e HF_TOKEN=hf_xxx'
vastai create instance <id> --image vastai/comfy:@vastai-automatic-tag --disk 40 --ssh --direct \
--env '-e CHECKPOINT_MODEL=black-forest-labs/FLUX.1-schnell -e HF_TOKEN=hf_xxx'
create instance flags:
--image IMAGE — Docker image
--disk DISK — Local disk in GB
--ssh / --jupyter — Connection type
--direct — Faster direct connections
--label LABEL — Instance label
--env ENV — Env vars and port mappings, e.g. '-e TZ=UTC -p 8080:8080'
--onstart FILE — Path to a startup script file
--onstart-cmd CMD — Startup script as inline string (for longer scripts use --onstart or gzip+base64 encode)
--bid_price PRICE — Interruptible (spot) pricing in $/hr
--template_hash HASH — Create from template
--create-volume ID — Attach new volume
--link-volume ID — Attach existing volume
--cancel-unavail — Fail if no machine available (vs. create stopped)
Instance status values:
actual_status | Meaning |
|---|
null | Provisioning |
created | Instance created, not yet provisioned |
loading | Image downloading / container starting |
running | Active — GPU charges apply |
stopped | Halted — disk charges only |
frozen | Paused with memory — GPU charges apply |
exited | Container process exited unexpectedly |
rebooting | Restarting (transient) |
unknown | No recent heartbeat from host |
offline | Host disconnected from Vast servers |
Poll loop warning: If actual_status becomes exited, unknown, or offline it will never reach running. Always add a timeout and error branch — otherwise your script loops forever while disk charges accrue. Destroy and retry with a different offer.
Charges: Storage charges begin at creation. GPU charges begin when status reaches running.
Search
vastai search offers
vastai search offers 'gpu_name=RTX_4090 num_gpus=1 verified=true direct_port_count>=1' -o 'dlperf_usd-'
vastai search offers 'num_gpus>=4 reliability>0.99' -o 'num_gpus-'
vastai search offers --type bid
vastai search offers --type reserved
vastai search offers -n 'gpu_name=H100_SXM'
vastai search volumes
vastai search templates "pytorch"
vastai search benchmarks
vastai search invoices
search offers flags: --type on-demand|reserved|bid, --order/-o FIELD[-], --limit, --storage GB, --no-default/-n
SSH & File Transfer
vastai ssh-url <id>
vastai scp-url <id>
vastai attach ssh <id> "ssh-ed25519 AAAA..."
vastai detach ssh <id> <ssh_key_id>
vastai show ssh-keys
vastai create ssh-key ~/.ssh/id_ed25519.pub
vastai create ssh-key
vastai create ssh-key "ssh-ed25519 AAAA..."
vastai delete ssh-key <id>
vastai update ssh-key <id> "ssh-ed25519 AAAA..."
Note: ssh-url returns a connection string — it does not open an interactive session. Use $(vastai ssh-url <id>) to extract the URL, or parse --raw JSON output.
File Copy
vastai copy <src> <dst>
vastai copy local:./data/ <id>:/workspace/data/
vastai copy <id>:/workspace/results/ local:./results/
vastai copy <id-a>:/workspace/ <id-b>:/workspace/
vastai cloud copy --src ./data --dst s3://bucket/path \
--instance 12345 --connection <conn-id> \
--transfer "Instance To Cloud"
vastai cancel copy <dst-id>
cloud copy flags: --src, --dst, --instance, --connection, --transfer
Logs & Exec
vastai logs <id>
vastai logs <id> --tail 100
vastai logs <id> --filter "error"
vastai execute <id> "nvidia-smi"
vastai execute <id> "ls /workspace" --schedule DAILY
Volumes
vastai search volumes
vastai show volumes
vastai create volume <offer_id> [-s SIZE] [-n NAME]
vastai clone volume <source_id> <dest_id> [-s SIZE]
vastai delete volume <id>
vastai create network-volume ...
vastai list network-volume
vastai take snapshot <instance_id> --repo REPO --docker_login_user USER --docker_login_pass PASS
Serverless & Deployments
vastai show endpoints
vastai create endpoint --name "my-ep" ...
vastai update endpoint <id> ...
vastai delete endpoint <id>
vastai get endpt-logs <id>
vastai show workergroups
vastai create workergroup --name "wg" ...
vastai update workergroup <id> ...
vastai update workers <id>
vastai delete workergroup <id>
vastai get wrkgrp-logs <id>
vastai show deployments
vastai show deployment <id>
vastai show deployment-versions <id>
vastai delete deployment <id>
vastai show scheduled-jobs
vastai delete scheduled-job <id>
Templates
vastai search templates "pytorch"
vastai create template --name "x" --image "img"
vastai update template <id> ...
vastai delete template <id>
Account & API Keys
vastai set api-key <key>
vastai show api-key <id>
vastai show api-keys
vastai create api-key --name "ci" --permissions '{...}'
vastai delete api-key <id>
vastai reset api-key
vastai show user
vastai show audit-logs
vastai show connections
vastai show ipaddrs
Billing
vastai show invoices-v1
vastai show invoices-v1 --charges
vastai show invoices-v1 --invoices
vastai show invoices-v1 --start-date 2026-01-01 --end-date 2026-02-01
vastai show invoices-v1 --limit 50 --latest-first
vastai show deposit <id>
Teams
vastai create team --name "myteam"
vastai show members
vastai invite member --email user@example.com
vastai remove member <id>
vastai create team-role --name "viewer" ...
vastai show team-role <id>
vastai show team-roles
vastai update team-role <id> ...
vastai remove team-role <id>
vastai destroy team
Environment Variables
User-scoped environment variables that get injected into instances at launch — used for API tokens (HuggingFace, OpenAI, etc.) and model config.
vastai show env-vars --raw
vastai create env-var HF_TOKEN hf_abc123 --raw
vastai update env-var HF_TOKEN hf_new456 --raw
vastai delete env-var HF_TOKEN --raw
Common prompts and the calls they map to:
- "set HF_TOKEN to hf_xxxxx" →
vastai create env-var HF_TOKEN hf_xxxxx --raw
- "add a HuggingFace token" → ask for the token value, then
vastai create env-var HF_TOKEN <value> --raw
- "list my env vars" →
vastai show env-vars --raw
- "unset OPENAI_API_KEY" →
vastai delete env-var OPENAI_API_KEY --raw
Machine Management (hosts)
vastai show machines
vastai list machine <id>
vastai show machine <id>
vastai cleanup machine <id>
vastai schedule maint <id> ...
vastai cancel maint <id>
vastai show maints
vastai unlist machine <id>
Common errors
| Error | Cause | Fix |
|---|
401 Unauthorized | Invalid or expired API key | vastai set api-key <new-key> |
Insufficient credits | Account balance too low | Add credits at https://cloud.vast.ai/billing/ |
No offers found | Filters too restrictive | Relax filters, try --no-default/-n |
Permission denied | SSH key not attached | vastai create ssh-key before create instance |
Connection refused | Instance not yet running | Poll show instance <id> until actual_status == "running" |
Hangs on destroy instance | Confirmation prompt waiting for input | Add -y flag: vastai destroy instance <id> -y |
URLs
Console
https://console.vast.ai/instances/ # Your instances
https://console.vast.ai/create/ # Search GPU offers
https://console.vast.ai/manage-keys/ # Create and manage API keys
https://cloud.vast.ai/billing/ # Billing
API
https://console.vast.ai/api/v0/instances/ # Instances endpoint
https://console.vast.ai/api/v0/asks/ # Offers search
Instance Ports
Access a port exposed on your instance:
ssh://root@<ssh_host>:<ssh_port> # SSH (from vastai ssh-url)
Direct connections (when --direct used at creation): <direct_port_end> field in instance JSON.
Documentation
Fetch the complete documentation index at: https://docs.vast.ai/llms.txt