Skip to main content

Introduction

Instance creation on Vast.ai follows a two-step process: first find an offer (an available machine), then accept that offer to create an instance. You can configure instances in two ways:
  • Directly: Pass all configuration (image, environment variables, launch mode, etc.) in the instance creation request
  • From a template: Reference a pre-configured template by its hash_id, optionally overriding specific values
Both approaches use the same endpoint: PUT /api/v0/asks/{offer_id}/. For information about creating and managing templates, see Creating and Using Templates with API.

Instance Creation Fields Reference

When creating an instance, the following fields can be configured:

Step 1: Find an Offer

Before creating an instance, search for available machines that match your requirements.
The offer id returned from search is the value you pass as {offer_id} in the instance creation endpoint.

Step 2: Create the Instance

Option A: Create Instance Directly (No Template)

Pass all configuration parameters directly in the request. At minimum, you must provide the image field. Simple example, create an SSH instance with Ubuntu:
Full example, SSH instance running a vLLM inference server:

Option B: Create Instance from a Template

Reference a template by its hash_id. The template provides default values for all configuration fields, so you don’t need to specify image or other parameters unless you want to override them. Basic template usage, all configuration comes from the template:
Template with overrides, use a template but customize specific values:

Runtype and Connection Options

The runtype field controls how you connect to your instance:
All Jupyter runtypes implicitly include SSH access. Only the _direct runtypes provision ports on the instance itself, jupyter_direct provisions ports 8080 and 22, while ssh_direct provisions port 22. Proxy runtypes route connections through Vast.ai’s infrastructure without opening ports on the instance.
Recommendation: Use runtype: "jupyter_direct" for the most flexibility, you get both direct Jupyter and direct SSH access with ports provisioned on the instance. Use runtype: "ssh_direct" if you only need SSH.

Entrypoint Behavior

How the container starts depends on the runtype:
  • SSH and Jupyter runtypes: The image’s original entrypoint is replaced by Vast’s own entrypoint, which sets up SSH/Jupyter access. Use the onstart field to run your own startup commands (e.g., launching a server). Your onstart script runs after the Vast entrypoint has initialized.
  • args runtype: The image’s original ENTRYPOINT is preserved. The args_str value replaces the image’s Docker CMD, if the image defines an ENTRYPOINT, args_str is passed as arguments to it. If the image has no ENTRYPOINT (only CMD), args_str replaces the command entirely. No SSH or Jupyter access is provisioned.
If you use an SSH or Jupyter runtype without an onstart command, the container will start with only SSH/Jupyter access, your application won’t run automatically. Use onstart to start your services.

Runtype Examples

Jupyter Lab with SSH (recommended), use onstart to start your application:
SSH with a vLLM server, the server is started via onstart:
Entrypoint arguments (headless), args_str replaces the image’s CMD and is passed to its ENTRYPOINT:

Environment Variables and Ports

When creating instances, the env field is a JSON object (dict). Environment variables are key-value pairs, and port mappings use the Docker -p syntax as keys with "1" as the value.
When using a template, the env dict from your request is merged with the template’s env:
  • Existing keys from the template are retained
  • New keys from the request are added
  • Conflicting keys use the request value
See Precedence Rules in the templates guide for full details.

Instance Pricing

On-Demand Instances

On-demand instances use fixed pricing. Simply omit the price field:

Interruptible (Bid) Instances

For lower-cost interruptible instances, set a bid price. Search with type: "bid" to find interruptible offers, then provide the price field:

Attaching Volumes

Attach persistent storage to your instance using the volume_info field. The volume must already exist, you can create volumes separately via the API or CLI before attaching them to an instance.
You can list your existing volumes with vastai show volumes or the equivalent API call to find the volume_id to use.

Using Private Docker Images

If your Docker image is hosted in a private registry, provide credentials via the image_login field:
When using a template with private registry credentials (docker_login_repo, docker_login_user, docker_login_pass), those credentials carry over to the instance automatically.

End-to-End Example

This example shows the complete workflow: searching for a machine, creating an instance, and checking its status.

CLI Reference

The Vast.ai CLI provides equivalent commands for instance creation: Common create instance options:
  • --image IMAGE - Docker image
  • --template_hash HASH - Template hash ID
  • --disk GB - Disk space in GB
  • --ssh - Launch as SSH instance
  • --direct - Use direct connections
  • --jupyter - Launch as Jupyter instance
  • --jupyter-lab - Use JupyterLab
  • --env ENV - Docker options (env vars and ports)
  • --onstart-cmd CMD - Onstart script
  • --label LABEL - Instance name
  • --price PRICE - Bid price for interruptible instances
  • --link-volume ID - Attach an existing volume
  • --mount-path PATH - Volume mount path
Example CLI commands:

Common Pitfalls

Ensure you set the correct runtype. For SSH access, use runtype: "ssh_direct" for best results. Also verify that:
  • You have an SSH key registered with Vast.ai (vastai create ssh-key)
  • The machine supports direct connections (most verified machines do)
  • The instance has finished loading (check actual_status is running)
For instance creation, the env field must be a JSON object (dict), not a Docker flag string:
  • Correct: {"VAR1": "value1", "VAR2": "value2"}
  • Wrong: "-e VAR1=value1 -e VAR2=value2"
Port mappings use the -p syntax as keys with "1" as the value: {"-p 8000:8000": "1"}Note: Template creation still uses the Docker flag string format.Also note that environment variables set via env are not automatically visible in SSH sessions. To make them available when you SSH in, add the following to your onstart script:
This exports all environment variables so they persist across SSH logins.
Offers are dynamic, machines can be rented by others between your search and creation request. Handle this by:
  • Searching for multiple offers and trying the next one if creation fails
  • Using cancel_unavail: true to fail fast if the offer is no longer available
  • Retrying the search to find fresh offers
Interruptible instances can be stopped when someone outbids you. To reduce interruptions:
  • Increase your bid price
  • Choose machines with lower demand
  • Consider on-demand instances for critical workloads (omit price field)
The volume_info field must be included in the instance creation request, not just the template. Template volume_info is a UI hint only.The volume must already exist before you can attach it. Ensure you provide the correct structure:
Where volume_id is the ID of an existing volume from vastai show volumes.

Templates Guide

Create and manage templates for instance configuration

Create Instance API

Full API reference for the instance creation endpoint

Search Offers API

Find available machines to rent

Instance Types

On-demand vs interruptible vs reserved instances