Skip to main content
The VastAI class is the main client for interacting with the Vast.ai platform. It wraps the CLI commands as Python methods with typed signatures.

Installation

pip install vastai-sdk

Quick Start

from vastai import VastAI

client = VastAI(api_key="YOUR_API_KEY")

# Search for GPU offers
offers = client.search_offers(query="gpu_name=RTX_3090 rentable=True")
print(offers)

# Show your instances
instances = client.show_instances()
print(instances)

Constructor

VastAI(
    api_key=None,
    server_url="https://console.vast.ai",
    retry=3,
    raw=True,
    explain=False,
    quiet=False,
    curl=False
)
api_key
Optional[str]
default:"None"
Your Vast.ai API key. If not provided, reads from ~/.config/vastai/vast_api_key.
server_url
str
default:"\"https://console.vast.ai\""
The Vast.ai API server URL.
retry
int
default:"3"
Number of retry attempts for failed API requests.
raw
bool
default:"True"
Return raw JSON responses instead of formatted output.
explain
bool
default:"False"
Print verbose explanations of API calls.
quiet
bool
default:"False"
Suppress non-essential output.
curl
bool
default:"False"
Print equivalent curl commands for API calls.
If api_key is not provided, the SDK reads it from ~/.config/vastai/vast_api_key.

Getting Help

Use Python’s built-in help() to view documentation for any method:
help(client.search_offers)