# Vast.ai Adapter

**Interface:** `vastai` CLI. **Kind:** marketplace instances. **Cheapest lane, most hands-on.**

## Install & auth

```bash
pip install -U vastai
vastai set api-key $VAST_API_KEY     # key: vast.ai → Settings → API Keys
vastai show instances --raw          # verify (empty list is fine)
```

## Provision

```bash
# 1. search — ALWAYS before provisioning; this is a live market
vastai search offers 'gpu_name=RTX 5090' --order 'dph_total asc' --limit 10 --raw
#   sanity filters: --storage '>= 60' --num-gpus 1 --verified
#   read the JSON: id (bundle), dph_total (all-in $/hr), gpu_ram, disk_space,
#   geolocation, dlperf (benchmark), cuda_max_good

# 2. create (ssh + direct ports for API access)
vastai create instance <bundle_id> --disk 60 --image nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04 --ssh --direct
#   --onstart-cmd can pre-bootstrap, e.g. installing comfyui

# 3. wait for ready
vastai show instance <id>            # status: running, ssh_host/ssh_port appear
```

## SSH & destroy

```bash
ssh -p <ssh_port> root@<ssh_host>    # key added by --ssh
vastai destroy instance <id>
```

## Gotchas

- **Storage is billed hourly** — `dph_total` includes the offer's disk; adding
  disk via `--disk` raises the all-in rate. Right-size it (weights + outputs,
  not your whole life).
- **Interruptible** offers are cheaper and reclaimable. Retryable batch → fine.
  One-shot → avoid.
- `--direct` exposes public ports (needed for the ComfyUI API); without it you
  get an encrypted proxy and must SSH-tunnel.
- **Check `cuda_max_good`**: pick offers whose CUDA supports your torch build,
  or install a matching torch (comfyui skill).
- Offers vanish; a great price can be gone in minutes. Search → provision in
  the same session, don't pre-plan a specific bundle id.
- `dph` (GPU-only) is bait — always compare `dph_total`.

## Reference

- CLI docs: https://docs.vast.ai/cli (search/create/destroy flags)
- Live API: `GET https://vast.ai/api/v0/bundles?q=<json>` (no auth for basic queries)
- Snapshot baseline: docs/pricing/vast.md
