Prerequisites
- A Vast.ai account with credit (~$0.01-0.05, depending on test instance run time)
- Python 3 installed
1. Install the SDK
Install from PyPI:2. Authenticate
Import the SDK and create a client with your API key. Generate an API key from the Keys page by clicking +New. Copy the key, you’ll only see it once.vastai set api-key), the SDK reads it automatically from ~/.config/vastai/vast_api_key, no need to pass it explicitly:
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:
Note the
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. Create an Instance
Rent the machine usingcreate_instance with the offer ID from step 4:
The output includes the new instance ID:
new_contract value, this is your instance ID.
Storage charges begin at creation. GPU charges begin when the instance reaches the
running state.6. Wait Until Ready
The instance needs time to pull the Docker image and boot. Check the status:
Boot time is typically 1-5 minutes depending on the Docker image size.
7. Connect via SSH
Once the instance is running, get the SSH connection details:8. Copy Data
Usecopy to transfer files between your local machine and the instance:
9. 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):Getting Help
Use Python’s built-inhelp() to view detailed documentation for any SDK method:
Next Steps
You’ve now completed the full instance lifecycle through the SDK: 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 method reference, See the SDK reference for every available method.
- Use templates, Avoid repeating image and config parameters on every create call. See the templates guide for creating and managing templates.
- Permissions, Create scoped API keys for CI/CD or shared tooling. See the permissions guide.