> ## Documentation Index
> Fetch the complete documentation index at: https://vastai-80aa3a82-docs-screenshot-updates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# create template

> Creates a new template for launching instances.

Templates store default configuration values that can be used when creating instances. When an instance is created with a template reference, template values serve as defaults that can be overridden by request parameters.

For detailed usage, see [Creating and Using Templates with API](/api-reference/creating-and-using-templates-with-api).

CLI Usage: `vastai create template --name <name> --image <image> [options]`



## OpenAPI

````yaml /api-reference/openapi.yaml post /api/v0/template/
openapi: 3.1.0
info:
  title: Vast.ai API
  description: >-
    Vast.ai REST API for managing GPU cloud instances, machine operations, and
    AI/ML workflows.


    ## AI Agent Quick-Start


    Install the CLI skill for your agent (Claude Code, Cursor, Windsurf, etc.):
      npx skills add vast-ai/vast-cli

    CLI reference:
    https://raw.githubusercontent.com/vast-ai/vast-cli/master/vastai/SKILL.md

    SDK reference:
    https://raw.githubusercontent.com/vast-ai/vast-cli/master/vastai_sdk/SKILL.md


    ## Auth

    All endpoints require `Authorization: Bearer $VAST_API_KEY`.

    Get your key at: https://cloud.vast.ai/manage-keys/


    ## Key Quirks

    - `gpu_ram` in CLI = GB; in REST API = MB (CLI auto-converts)

    - SSH keys must be registered BEFORE creating an instance (VM: no recovery;
    Docker: can add post-create)

    - `onstart` field is limited to 4048 characters -- gzip+base64 for longer
    scripts

    - `POST /api/v0/asks/{id}/` (create instance) returns `new_contract` as the
    instance ID, not `id`

    - Poll trap: if `actual_status` becomes `exited`, `unknown`, or `offline` it
    will never reach `running` -- destroy and retry
  version: 1.0.0
  contact:
    name: Vast.ai Support
    url: https://discord.gg/vast
servers:
  - url: https://console.vast.ai
    description: Production server
security:
  - BearerAuth: []
paths:
  /api/v0/template/:
    post:
      tags:
        - Templates
      summary: create template
      description: >-
        Creates a new template for launching instances.


        Templates store default configuration values that can be used when
        creating instances. When an instance is created with a template
        reference, template values serve as defaults that can be overridden by
        request parameters.


        For detailed usage, see [Creating and Using Templates with
        API](/api-reference/creating-and-using-templates-with-api).


        CLI Usage: `vastai create template --name <name> --image <image>
        [options]`
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - image
              properties:
                name:
                  type: string
                  default: Example Template
                  description: Name of the template
                image:
                  type: string
                  default: vastai/base-image
                  description: >-
                    Docker image path. Used when launching instances from this
                    template.
                tag:
                  type: string
                  default: latest
                  description: >
                    Docker image tag specifying version of the image. Defaults
                    to `latest`. Can also be included in the `image` field
                    instead.
                env:
                  type: string
                  description: >
                    Environment variables and port mappings in Docker flag
                    format.


                    Example: `"-e HF_TOKEN=hf_xxx123456789 -e
                    MODEL_ID=TheBloke/Llama-2-7B-Chat-GPTQ -p 8000:8000"`
                onstart:
                  type: string
                  description: >
                    Commands to run when instance starts


                    Example : `env | grep _ >> /etc/environment; echo 'starting
                    up'` 
                runtype:
                  type: string
                  enum:
                    - ssh
                    - jupyter
                    - args
                  default: args
                  description: >
                    Launch mode for the instance. Defaults to `args`.
                    Recommended - use `ssh` with `ssh_direct: true` for reliable
                    SSH access.
                ssh_direct:
                  type: boolean
                  description: Enable direct SSH connection
                jup_direct:
                  type: boolean
                  description: Enable direct Jupyter connection
                jupyter_dir:
                  type: string
                  description: |
                    Directory to launch Jupyter from

                    Example : `/home/notebooks`
                use_jupyter_lab:
                  type: boolean
                  description: Use JupyterLab instead of Jupyter Notebook
                docker_login_repo:
                  type: string
                  description: Name of the private Docker repo (i.e docker.io)
                docker_login_user:
                  type: string
                  description: Username for private Docker repo
                docker_login_pass:
                  type: string
                  description: Access token or password for private Docker repo.
                extra_filters:
                  type: object
                  description: >
                    Additional machine search filters. Example:
                    `{"cuda_max_good": {"gte": 12.6}}`
                recommended_disk_space:
                  type: number
                  description: >-
                    Recommended disk space in GB. Defaults to 8GB if not
                    specified.
                desc:
                  type: string
                  description: Short description of the template
                readme:
                  type: string
                  description: Longer documentation/readme content for the template
                args_str:
                  type: string
                  description: >-
                    Arguments string passed to the container entrypoint when
                    runtype is `args`
                use_ssh:
                  type: boolean
                  description: Enable SSH access to instances created from this template
                href:
                  type: string
                  description: Link to Docker Hub or image documentation
                repo:
                  type: string
                  description: Repository identifier (e.g., `library/ubuntu`)
                private:
                  type: boolean
                  description: Whether the template is private (not publicly searchable)
                volume_info:
                  type: object
                  nullable: true
                  description: >
                    UI hint for volume configuration. Note: This does not affect
                    instance creation - use `volume_info` in the instance
                    creation request to actually attach volumes.
                hash_id:
                  type: string
                  description: >-
                    Content-based hash ID of the template. Can be included when
                    editing but will change based on new content.
            example:
              name: Example Template
              image: vastai/base-image
              tag: latest
              env: '-e MY_VAR=value -p 8000:8000'
              runtype: ssh
              ssh_direct: true
      responses:
        '200':
          description: Template created or existing template found
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Whether operation was successful
                  msg:
                    type: string
                    description: Status message
                    example: 'Template Created Successfully! New Template ID: 123456'
                  template:
                    type: object
                    description: Template details
                    properties:
                      name:
                        type: string
                        description: Template name
                      id:
                        type: integer
                        description: Template ID
                      hash_id:
                        type: string
                        description: Template hash identifier
        '400':
          description: Bad request - invalid parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: invalid_args
                  msg:
                    type: string
                    example: Template name is required
        '401':
          description: Unauthorized - invalid or missing API key
        '429':
          description: Rate limit exceeded
      security:
        - BearerAuth: []
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key must be provided in the Authorization header

````