Prerequisites
- A Vast.ai account with credit (~$0.01-0.05, depending on test instance run time)
curlinstalled
1. Get Your API Key
Generate an API key from the Keys page by clicking +New. Copy the key, you’ll need it for your API calls, and you’ll only see it once. Export it as an environment variable:2. Verify Authentication
Confirm your key works by listing your current instances. If you have none, this returns an empty list.If you get a
401 or 403, double-check your API key. If you already have instances, you’ll see them listed here.3. Search for GPUs
Find available machines using the bundles endpoint. This query returns the top 5 on-demand RTX 4090s sorted by deep learning performance benchmarked per dollar:
The response contains an
offers array. 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).
4. Create an Instance
Rent the machine by sending a PUT request with your Docker image and disk size. ReplaceOFFER_ID with the id from step 3. disk is in GB and specifies the size of the disk on your new instance.
new_contract value, this is your instance ID. The instance_api_key is a restricted key injected into the container as CONTAINER_API_KEY, it can only start, stop, or destroy that specific instance.
5. Wait Until Ready
The instance needs time to pull the Docker image and boot. Poll the status endpoint untilactual_status is "running". Replace INSTANCE_ID with the new_contract value from step 4.
actual_status field progresses through these states:
Poll every 10 seconds. Boot time is typically 1-5 minutes depending on the Docker image size. You can also use the
onstart script to send a callback when the instance is ready, instead of polling.
Once actual_status is "running", you’re ready to connect.
6. Connect via SSH
Use thessh_host and ssh_port from the status response to connect directly to your new instance:
7. 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):{"success": true}.
Next Steps
You’ve now completed the full instance lifecycle through the API: authentication, search, creation, polling, and teardown. From here:- Full endpoint reference, Every REST endpoint is documented in the API reference, organized under the Reference tab.
- Authentication & permissions, Create scoped API keys for CI/CD or shared tooling. See API authentication and permissions.
- SSH setup, See the SSH guide for key configuration and advanced connection options.
- Use templates, Avoid repeating image and config parameters on every create call. The Templates API guide covers creating, sharing, and launching from templates.