Skip to main content
We provide a python CLI (open-source) for managing Vast.ai resources from the command line. You can use the —explain option with any CLI command to see the underlying API calls if needed.

PyPI Install

You can install the latest stable PyPI release with:
Text

Github

Alternatively you can get the very latest version directly from github:
Text
This repository contains the open source python command line interface for vast.ai. This CLI has all of the functionality of the vast.ai website GUI and uses the same underlying REST API. The CLI is self-contained in the single script file vast.py.

Quickstart

In order to authenticate most commands you will need to first login to the vast.ai website and get an api-key. Go to https://cloud.vast.ai/cli/. Copy the command under the heading “Login / Set API Key” and run it. The command will be something like: vastai set api-key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx where the xxxx... is a unique api-key (a long hexadecimal number). Note that if the script is named “vast” in this command on the website and your installed script is named “vast.py” you will need to change the name of the script in the command you run. The set api-key command saves your api-key in a hidden file in your home directory. Do not share your api-keys with anyone as they authenticate commands from your account. Your default main key allows full access to all commands without limitations. To create restricted keys, use the create api-key command (see CLI commands) with the permission JSON structure described in the permissions documentation.

Usage

For the most up to date help, use ‘vast.py —help’. You can then get a list of the available commands. Each command also typically has help documentation:
Text
Here’s how to search for available machines to rent:
Text
There are many parameters that can be used to filter the results. The search command supports all of the filters and sort options that the website GUI uses. To find GPU instances with compute capability 8.0 or higher:
Text
To find instances with a reliability score >= 0.99 and at least 4 gpus, ordering by num of gpus descending:
Text
The output of this command at the time of this writing is
Text

Launching Instances

Text
You create instances using the create instance command referencing an instance type ID returned from search offers. So to create an ssh direct instance of type 2459368 (using the ID returned from the search above for 4x 3090 on machine 4637) with the vastai/tensorflow image and 32 GB of disk storage:
Text
Once an instance is created, it then must first pull the image if it is not cached. After the image is loaded the instance boots and transititons to the running state. You are charged for the resources you reserve. As storage is reserved at creation, storage charges begin when the instance is created and end only when it is destroyed. GPU charges begin when the instance transitions to the running state, and end when it is stopped or destroyed.

Get Instance Info

Text

Starting Stopping

Text
You can stop an instance to avoid GPU charges, converting it into a storage unit - storage is usually very cheap compared to GPU. Starting an existing instance takes only a second or less whereas creating a new instance can take much longer (to pull a large docker image), so maintaining a pool of stopped instances is useful for many applications. You can call stop/destroy instance from inside the instance using a special autogenerated instance apikey, to avoid exposing your main apikey.

Copy Data

Text
You can copy data from a stopped instance to a running instance, to/from cloud storage, or to/from another machine.

Destroy Instances

Text
Once you are done with an instance make sure to destroy it to avoid ongoing storage charges.