CLI and SDK for Vast.ai GPU Cloud Service
Project description
Vast.ai Python SDK & CLI
The official Vast.ai Python package — provides both the CLI and SDK for managing Vast.ai GPU cloud resources, plus a serverless client for endpoint inference.
Install
pip install vastai
Note:
pip install vastai-sdkalso works and installs the same package. Both package names are supported for backward compatibility.
Quickstart
-
Get your API key from https://cloud.vast.ai/manage-keys/
-
Set your API key:
vastai set api-key YOUR_API_KEY
- Test a search:
vastai search offers --limit 3
You should see a short list of available GPU offers.
CLI Usage
The vastai command provides full access to the Vast.ai platform from your terminal:
vastai search offers 'gpu_name=RTX_4090 num_gpus>=4'
vastai create instance 12345 --image pytorch/pytorch --disk 32 --ssh --direct
vastai show instances
vastai stop instance 12345
vastai destroy instance 12345
Run vastai --help for a full list of commands. You can also use --help on any subcommand:
vastai search offers --help
vastai create instance --help
SDK Usage
from vastai import VastAI
vast = VastAI() # uses VAST_API_KEY env var, or pass api_key="..."
vast.search_offers(query='gpu_name=RTX_4090 num_gpus>=4')
vast.show_instances()
vast.start_instance(id=12345)
vast.stop_instance(id=12345)
Use help(vast.search_offers) to view documentation for any method.
Migrating from
vastai-sdk? The old import still works:from vastai_sdk import VastAI
Using the Serverless Client
- Create the client
from vastai import Serverless
serverless = Serverless() # or, Serverless("YOUR_API_KEY")
- Get an endpoint
endpoint = await serverless.get_endpoint("my-endpoint")
- Make a request
request_body = {
"model": "Qwen/Qwen3-8B",
"prompt" : "Who are you?",
"max_tokens" : 100,
"temperature" : 0.7
}
response = await serverless.request("/v1/completions", request_body)
- Read the response
text = response["response"]["choices"][0]["text"]
print(text)
Find more examples in the examples/ directory.
Tab Completion
Tab completion is supported in Bash and Zsh via argcomplete (installed automatically). To enable it:
activate-global-python-argcomplete
Or for a single session:
eval "$(register-python-argcomplete vastai)"
Contributing
This repository is open source. If you find a bug, please open an issue. PRs are welcome.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vastai-1.0.1.tar.gz.
File metadata
- Download URL: vastai-1.0.1.tar.gz
- Upload date:
- Size: 196.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.12.13 Linux/6.17.0-1010-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe23c879b7f3cb90c58867c7cd64e67e3be7c8db04d391da40e0f035e7b91784
|
|
| MD5 |
c8a4a462e96cdab5fd65d4c1eff27b85
|
|
| BLAKE2b-256 |
7f59c106f22c6b6f5d51e689cdf529cab5d550bd685441ee3450c339bf3cf8b1
|
File details
Details for the file vastai-1.0.1-py3-none-any.whl.
File metadata
- Download URL: vastai-1.0.1-py3-none-any.whl
- Upload date:
- Size: 227.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.12.13 Linux/6.17.0-1010-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccb314b9fdef0bfd8f28e1ebec483e68b8bff41d64af58b776c8ee19082b032a
|
|
| MD5 |
678d4016d6fda8a200f6656a4c17c1a7
|
|
| BLAKE2b-256 |
ea3240f4ca0842a6a1f26e01576907de57903497ffcad4cd3ee225ca977fa962
|