Vast.ai Python SDK
The official Python SDK for Vast.ai, providing programmatic access to GPU cloud resources. Users install the `vastai-sdk` package, which then exposes the `VastAI` client class through the `vastai` module. This SDK allows for searching, launching, and managing GPU instances, mirroring much of the functionality of the Vast.ai CLI. The current version is 0.6.0, with active development.
Warnings
- gotcha The PyPI page for `vastai-sdk` contains a misleading message stating 'DEPRECATED — use 'pip install vastai' instead.' However, `vastai-sdk` is the active, official SDK package, and `pip install vastai-sdk` is the correct way to get the SDK client, which then imports from the `vastai` module. This causes confusion between the SDK package and the underlying CLI module.
- gotcha The `vastai-sdk` package (the SDK) exposes its client class `VastAI` via the `vastai` module, not `vastai_sdk`. Users accustomed to standard Python package import conventions might attempt `from vastai_sdk import VastAI`, which will fail.
- breaking The GitHub repository provided in the prompt's live metadata (`https://github.com/vast-ai/vast-cli`) is for the `vastai` CLI client. The actual source repository for `vastai-sdk` is `https://github.com/vast-ai/vast-sdk`. This can lead to users consulting the wrong documentation or contributing to the incorrect project.
- gotcha The version provided in the prompt's live metadata (1.0.1) does not match the latest version on PyPI for `vastai-sdk`, which is 0.6.0 as of April 2, 2026. This discrepancy might indicate outdated information or confusion with another package.
Install
-
pip install vastai-sdk
Imports
- VastAI
from vastai import VastAI
Quickstart
import os
from vastai import VastAI
# Ensure VAST_API_KEY is set in your environment
# or pass it directly: vast = VastAI(api_key="YOUR_API_KEY")
api_key = os.environ.get('VAST_API_KEY', '')
if not api_key:
print("Error: VAST_API_KEY environment variable not set.")
print("Please visit https://cloud.vast.ai/cli/ to get your API key.")
else:
vast = VastAI(api_key=api_key)
try:
offers = vast.search_offers(query='num_gpus >= 1 gpu_name = RTX_3090', limit=1)
if offers:
print(f"Found an offer: {offers.get('gpu_name')} at {offers.get('dph_total')}$/hr")
else:
print("No matching offers found.")
except Exception as e:
print(f"An error occurred: {e}")