Skip to main content
Create a new instance from a contract offer ID.

Signature

VastAI.create_instance(
    id: int,
    price: Optional[float] = None,
    disk: Optional[float] = 10,
    image: Optional[str] = None,
    login: Optional[str] = None,
    label: Optional[str] = None,
    onstart: Optional[str] = None,
    onstart_cmd: Optional[str] = None,
    entrypoint: Optional[str] = None,
    ssh: bool = False,
    jupyter: bool = False,
    direct: bool = False,
    jupyter_dir: Optional[str] = None,
    jupyter_lab: bool = False,
    lang_utf8: bool = False,
    python_utf8: bool = False,
    extra: Optional[str] = None,
    env: Optional[str] = None,
    args: Optional[List[str]] = None,
    force: bool = False,
    cancel_unavail: bool = False,
    template_hash: Optional[str] = None
) -> str

Parameters

id
int
required
ID of the offer/contract to create the instance from (returned by search_offers).
price
Optional[float]
(OPTIONAL) Per-machine bid price in $/hour for interruptible (spot) instances.
disk
Optional[float]
default:"10"
Disk space to allocate in GB.
image
Optional[str]
Docker image name to use for the instance.
login
Optional[str]
Docker login credentials for private registry authentication.
label
Optional[str]
Label to attach to the instance.
onstart
Optional[str]
Filename of an onstart script to run on instance start.
onstart_cmd
Optional[str]
Shell command to run on instance start.
entrypoint
Optional[str]
Override the Docker image entrypoint.
ssh
bool
default:"False"
Enable SSH access to the instance.
jupyter
bool
default:"False"
Enable Jupyter notebook server.
direct
bool
default:"False"
Enable direct (peer-to-peer) connections.
jupyter_dir
Optional[str]
Directory to serve Jupyter from.
jupyter_lab
bool
default:"False"
Enable JupyterLab instead of classic Jupyter.
lang_utf8
bool
default:"False"
Set system language encoding to UTF-8.
python_utf8
bool
default:"False"
Set Python I/O encoding to UTF-8.
extra
Optional[str]
Extra Docker run arguments passed verbatim.
env
Optional[str]
Environment variables to set (formatted as Docker -e flags).
args
Optional[List[str]]
Additional positional arguments.
force
bool
default:"False"
Skip sanity checks when creating from an existing instance.
cancel_unavail
bool
default:"False"
Return an error if scheduling fails rather than creating a stopped instance.
template_hash
Optional[str]
Hash of an instance template to use for configuration.

Returns

str — Result from the API call.

Example

from vastai import VastAI

client = VastAI(api_key="YOUR_API_KEY")
result = client.create_instance(id=12345)
print(result)