The Vast.ai CLI gives you command-line access to the entire platform, authentication, GPU search, instance lifecycle, templates, volumes, serverless endpoints, and more. Anything you can do in the web console, you can automate from your terminal. This guide walks through the core workflow: install the CLI, authenticate, search for a GPU, rent it, wait for it to boot, connect to it, copy data, and clean up. By the end you’ll understand the commands needed to manage instances without touching the web console.Documentation Index
Fetch the complete documentation index at: https://docs.vast.ai/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A Vast.ai account with credit (~$0.01-0.05, depending on test instance run time)
- Python 3 installed
1. Install the CLI
Install from PyPI:2. Set Your API Key
Generate an API key from the Keys page by clicking +New. Copy the key, you’ll only see it once. Save it to the CLI:3. Verify Authentication
Confirm your key works by fetching your account info:4. Search for GPUs
Find available machines usingsearch offers. This query returns on-demand RTX 4090s on verified machines with direct port access, sorted by deep learning performance per dollar:
| Parameter | Meaning |
|---|---|
gpu_name=RTX_4090 | Filter to a specific GPU model |
num_gpus=1 | Exactly 1 GPU per instance |
verified=true | Only machines verified by Vast.ai (identity-checked hosts) |
direct_port_count>=1 | At least 1 directly accessible port (needed for direct SSH) |
rentable=true | Only machines currently available to rent |
-o 'dlperf_usd-' | Sort by DL performance per dollar, best value first |
ID of the offer you want, you’ll use it in the next step. If no offers are returned, try relaxing your filters (e.g. a different GPU model or removing direct_port_count).
5. Register Your SSH Key
Do this before creating an instance. Your SSH public key must be registered on your account, it is applied at container creation time.6. Create an Instance
Rent the machine usingcreate instance with the offer ID from step 4 (search):
| Flag | Meaning |
|---|---|
--image | Docker image to launch |
--disk 20 | 20 GB of disk storage |
--onstart-cmd | Command to run when the instance boots |
--ssh --direct | Direct SSH access (lower latency than proxy SSH) |
new_contract value, this is your instance ID.
Storage charges begin at creation. GPU charges begin when the instance reaches the
running state.--onstart-cmd is limited to 16KB. For longer scripts, gzip and base64 encode them, see the Template Settings page for the workaround.7. Wait Until Ready
The instance needs time to pull the Docker image and boot. Check the status with:status field progresses through these states:
| Status | Meaning |
|---|---|
loading | Docker image is downloading |
running | Ready to use |
8. Connect via SSH
Once the instance is running, get the SSH connection details:9. Copy Data
Usevastai copy to transfer files between your local machine and the instance:
10. Clean Up
When you’re done, destroy the instance to stop all billing. Alternatively, to pause an instance temporarily instead of destroying it, you can stop it. Stopping halts compute billing but disk storage charges continue. Destroy (removes everything):Next Steps
You’ve now completed the full instance lifecycle through the CLI: installation, authentication, search, creation, polling, data transfer, and teardown. From here:- SSH setup, See the SSH guide for key configuration and advanced connection options.
- Full command reference, Every CLI command is documented under the Reference tab, grouped by domain (Accounts, Instances, Search, Serverless, and more).
- Use templates, Avoid repeating image and config parameters on every create call. See the templates guide for creating and managing templates.