> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hivenet.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create instance

> Creates an instance of a preset with an image, and starts it. The
preset sets the region, location and hardware, and the instance is
billed at that preset's price, or at your organization's discounted
rate when that is lower. `hourly_rate` in the response is the rate
billed. Your account needs enough credit for one hour of the preset,
unless it is invoiced.

**Creates are not idempotent and names are not unique.** Each
successful call creates and bills a new instance, even with the same
body. If a create answers `500`, `503` or `504`, or the connection
drops, the instance may or may not exist: list your instances with
`GET /instances` before retrying.

Look the preset up with `GET /presets` before each create rather than
storing its `id`: a preset can be retired, which answers `404`, or
edited in place to a different size or price. Find it again by `sku`,
`region` and `location`, and check the size and `hourly_rate` in the
response.

The instance gets the SSH key you registered last, whether through
`POST /ssh-keys` or in the console. Without a key, the call answers
`404`.

Give `image_type` and `image_id` as `GET /images` lists them. The
image must suit the preset: for a virtual machine, a GPU preset needs
an image with `gpu_supported`; the preset must meet the image's
`min_disk_gb` and `min_memory_gb`; and the location must allow the
image's `os_family`. Otherwise the call answers `400`, with a fixed
message that does not say which rule failed. Windows images cannot be
created through the API in this release and are refused too.

Connection details are not part of the API in this release: neither
this response nor `GET /instances/{id}` carries a host or port. Find
them on the instance in the Hive Compute console.

Ports, environment variables, tags and a startup script are not
part of this release.


Create a Compute VM or container using a hardware preset and an image. The instance uses the last public key you registered through the API or the Compute console.

For the full workflow, see [Create an instance using the Compute API](https://docs.hivenet.com/public-api/create-an-instance-using-the-compute-api.md).

## Before you send the request

Choose a preset from [List presets](https://docs.hivenet.com/public-api/endpoints/list-presets.md) and an image from [List images](https://docs.hivenet.com/public-api/endpoints/list-images.md). The preset determines the hardware and location. Match `image_type` to the type used when listing images.

A prepaid account needs enough credit for one hour of the selected preset. Availability can change between listing presets and creating the instance.

## Request

All four fields are required in the JSON body.

| Field | Value |
| - | - |
| `name` | 1–255 letters, digits, hyphens, or underscores. Names can repeat. |
| `preset_id` | A current preset UUID from `GET /presets`. Look it up before each create because presets can change. |
| `image_type` | `vm` or `container`, case-insensitive. |
| `image_id` | An image ID from `GET /images` for that type, up to 255 characters. |

```bash theme={null}
curl --request POST \
  --url "https://api.hivecompute.ai/v1/instances" \
  --header "Authorization: Bearer $HIVENET_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "my-api-vm",
    "preset_id": "YOUR_PRESET_ID",
    "image_type": "vm",
    "image_id": "YOUR_IMAGE_ID"
  }'
```

Replace `YOUR_PRESET_ID` and `YOUR_IMAGE_ID` with values from the catalogue. For a container, use `image_type: "container"` and a container image ID.

## Response and readiness

A successful create returns `201 Created`. Read `instance.instance_id` from the response. If `instance` contains only `instance_id`, creation still succeeded. Poll [Get instance](https://docs.hivenet.com/public-api/endpoints/get-instance.md) until `status` reaches `RUNNING`. Creation can succeed before the instance is ready.

Use the connection command shown in the Compute console to connect.

## Errors and retries

| Status | What to check |
| - | - |
| `400` | Check the four fields and whether the image is compatible with the preset. |
| `401` | Supply a valid Compute API key. |
| `403` | Check account status and access to the preset’s location. |
| `404` | Check the registered SSH key, preset, image, and availability of the image in that location. |
| `409 CONFLICT` | Check credit and capacity, then refresh the preset in case it changed. These failures do not create an instance. |
| `429` | Wait the number of seconds in `Retry-After`. |
| `500`, `503`, `504` | The outcome is unknown. List instances before retrying. |

A no-capacity `409` does not include `Retry-After`. Choose another compatible preset or try again later.

> [!WARNING]
>
> Creation is not idempotent. Each successful call creates a separately billed instance, even with the same name and body. After a lost response, connection failure, or `500`, `503`, or `504`, check [List instances](https://docs.hivenet.com/public-api/endpoints/list-instances.md) before you submit again.

This release does not support startup scripts, tags, or renaming and retagging instances through `PATCH`.


## OpenAPI

````yaml public-v1.yaml POST /instances
openapi: 3.0.3
info:
  title: Hive Compute Public API
  description: |
    The Hive Compute public API lets you manage compute instances
    programmatically, and browse the hardware presets and regions available to
    you.

    This release of the API covers creating, reading and controlling
    instances, the images you can launch, and registering the SSH key your
    instances use. To create an instance, pick a preset from `GET /presets`
    and an image from `GET /images`, register an SSH key once with
    `POST /ssh-keys`, then call `POST /instances`.

    **Base URL:** `https://api.hivecompute.ai/v1`

    ## Authentication

    Every endpoint requires an API key, sent as a Bearer token:

    ```
    Authorization: Bearer <your-api-key>
    ```

    API keys are issued manually at this release. Email
    [support@hivenet.com](mailto:support@hivenet.com) to request one. There is
    no self-service endpoint or console page for creating, listing or rotating
    keys yet; both will arrive in a later release.

    Treat the key as a password. It carries the full permissions of your
    account, does not expire on its own, and can only be replaced by contacting
    support.

    ## Scope

    Requests are scoped to the account the key belongs to. You can only see and
    act on your own instances and SSH keys. Regions and presets are the shared
    public catalogue and look the same to everyone. The images you can launch
    depend on the locations your account can use.

    ## Errors

    Every error shares one envelope:

    ```json
    {
      "error": {
        "code": "NOT_FOUND",
        "message": "Not found.",
        "request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
      }
    }
    ```

    Quote `request_id` when contacting support: it identifies the exact request
    in our logs.

    Branch on `code`, never on `message`. Most messages are fixed strings
    chosen per status rather than a description of your particular request:
    `403` and `404` read the same every time, a `409` may say what to change
    (for example that a preset is sold out), and `401` has two fixed
    forms depending on whether the key was absent or rejected. Only
    `VALIDATION_ERROR` carries detail, and even there a malformed path id
    reports only that a UUID was expected, without naming the parameter. The
    underlying detail is internal; `request_id` is how we trace a specific
    failure.

    A request with no key gets `401`, unless its body is not valid JSON, its
    body is too large or its path cannot be decoded, which are rejected first.
    With a key, the format of the request is checked before the key itself: a
    malformed path id, or a parameter or body of the wrong type or out of
    range, gets `400` whether or not the key is valid. That `400` holds nothing
    about any account. Everything else is checked after the key, so an invalid
    key gets `401`.

    ## Rate limiting

    Requests are rate limited per API key, currently 60 requests per minute,
    with a separate budget for each endpoint. Calls to one endpoint do not use
    up another endpoint's budget, and a key counts the same wherever it calls
    from. Exceeding the limit returns `429` with a `Retry-After` header giving
    the number of seconds to wait. Treat the limit as subject to change and back
    off on `429` rather than pacing to a fixed number. The metrics endpoint
    shares one budget across instance IDs. Shared service protection can
    also return `429`. Use the delay in the response.

    ## Pagination

    Paginated endpoints return this envelope. `GET /regions` returns an array:

    ```json
    {
      "data": [],
      "pagination": { "next": "opaque-cursor", "size": 50 }
    }
    ```

    Pass `pagination.next` back as the `cursor` query parameter to fetch the
    following page. When it is `null` you have reached the last page. Cursors
    are opaque; do not construct or parse them.
  version: 1.0.0
  contact:
    name: Hive Compute Support
    email: support@hivenet.com
    url: https://hivenet.com
servers:
  - url: https://api.hivecompute.ai/v1
    description: Production
  - url: https://staging-api.hivecompute.ai/v1
    description: Staging
security:
  - bearerAuth: []
tags:
  - name: Instances
    description: >
      Compute instances are the core resource of the platform. Each instance

      runs a CPU or GPU workload on a hardware preset in a region, and moves

      through this lifecycle:


      `CREATED → DEPLOYED → STARTING → RUNNING → STOPPING → STOPPED →
      TERMINATING → TERMINATED`


      A stopped instance can be started again and keeps its storage. A

      terminated instance is gone permanently and cannot be recovered.
  - name: Catalogue
    description: |
      The regions and hardware presets available to launch instances on. This
      is shared public reference data, identical for every caller.
  - name: Images
    description: |
      The images an instance boots. A `vm` image is an operating system for a
      virtual machine. A `container` image is a template for a container
      instance: the Hive catalogue, or templates you saved yourself.
  - name: SSH keys
    description: |
      The public key you use to log in to your instances. Your account can
      hold more than one key. New instances get the key you registered last,
      whether through this API or in the console's Settings, and the console
      launches with that same key.
paths:
  /instances:
    post:
      tags:
        - Instances
      summary: Create an instance
      description: |
        Creates an instance of a preset with an image, and starts it. The
        preset sets the region, location and hardware, and the instance is
        billed at that preset's price, or at your organization's discounted
        rate when that is lower. `hourly_rate` in the response is the rate
        billed. Your account needs enough credit for one hour of the preset,
        unless it is invoiced.

        **Creates are not idempotent and names are not unique.** Each
        successful call creates and bills a new instance, even with the same
        body. If a create answers `500`, `503` or `504`, or the connection
        drops, the instance may or may not exist: list your instances with
        `GET /instances` before retrying.

        Look the preset up with `GET /presets` before each create rather than
        storing its `id`: a preset can be retired, which answers `404`, or
        edited in place to a different size or price. Find it again by `sku`,
        `region` and `location`, and check the size and `hourly_rate` in the
        response.

        The instance gets the SSH key you registered last, whether through
        `POST /ssh-keys` or in the console. Without a key, the call answers
        `404`.

        Give `image_type` and `image_id` as `GET /images` lists them. The
        image must suit the preset: for a virtual machine, a GPU preset needs
        an image with `gpu_supported`; the preset must meet the image's
        `min_disk_gb` and `min_memory_gb`; and the location must allow the
        image's `os_family`. Otherwise the call answers `400`, with a fixed
        message that does not say which rule failed. Windows images cannot be
        created through the API in this release and are refused too.

        Connection details are not part of the API in this release: neither
        this response nor `GET /instances/{id}` carries a host or port. Find
        them on the instance in the Hive Compute console.

        Ports, environment variables, tags and a startup script are not
        part of this release.
      operationId: createInstance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - preset_id
                - image_type
                - image_id
              properties:
                name:
                  type: string
                  maxLength: 255
                  pattern: ^[a-zA-Z0-9_-]+$
                  description: Letters, digits, hyphens and underscores.
                  example: training-run-1
                preset_id:
                  type: string
                  format: uuid
                  description: The `id` of a preset from `GET /presets`.
                image_type:
                  type: string
                  enum:
                    - vm
                    - container
                  description: The `type` of the image. Case-insensitive.
                image_id:
                  type: string
                  maxLength: 255
                  description: The `id` of an image from `GET /images` of that type.
                  example: ubuntu24.04
      responses:
        '201':
          description: The instance was created and is starting.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedInstance'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: |
            Your account cannot use the preset's location, or cannot create
            instances now, for example because it is suspended.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: |
            The preset or the image does not exist, the preset's location does
            not offer it, or you have registered no SSH key. The message is
            fixed and does not say which. A preset being edited at that moment
            can also answer `404` once; look it up again and retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: |
            The instance cannot be created right now: not enough credit, the
            preset is sold out in its location, or the preset was edited
            during the call. Nothing was created. Top up, or retry later.
            Availability is counted separately for virtual machines and
            containers, so if a sold-out answer persists, try the other
            `image_type` or another preset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/CreateOutcomeUnknown'
        '503':
          $ref: '#/components/responses/CreateOutcomeUnknown'
        '504':
          $ref: '#/components/responses/CreateOutcomeUnknown'
components:
  schemas:
    CreatedInstance:
      type: object
      properties:
        instance:
          description: |
            The instance, as `GET /instances/{id}` returns it. When it could
            not be read right after the create, it holds only `instance_id`:
            the instance exists, so read it with `GET /instances/{id}` rather
            than creating again.
          allOf:
            - $ref: '#/components/schemas/Instance'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - UNAUTHORIZED
                - FORBIDDEN
                - NOT_FOUND
                - VALIDATION_ERROR
                - CONFLICT
                - TOO_MANY_REQUESTS
                - SERVICE_UNAVAILABLE
                - INTERNAL_ERROR
              description: Stable, machine-readable error code.
            message:
              type: string
              description: Human-readable explanation. Do not match on this text.
            request_id:
              type: string
              description: Identifies this request in our logs. Quote it to support.
    Instance:
      type: object
      properties:
        instance_id:
          type: string
          format: uuid
          description: Unique identifier.
        name:
          type: string
          description: Display name.
          example: training-run-4
        status:
          type: string
          enum:
            - CREATED
            - DEPLOYED
            - STARTING
            - RUNNING
            - ERRORED
            - TERMINATING
            - TERMINATED
            - STOPPING
            - STOPPED
            - PAUSED
          description: |
            Current lifecycle state. `PAUSED` is a running instance whose host
            is in an outage: it is not stopped, and billing is suspended until
            the host is back.
        region:
          type: string
          description: |
            The datacenter location the instance runs in, which is narrower
            than a region: a region contains several locations.

            **This value cannot be passed back as the `region` filter on
            `GET /instances` or `GET /presets`** — those take a region code
            from `GET /regions` (`FR`), not a location (`france-2`). Filtering
            on a location returns an empty page rather than an error.
          example: france-2
        gpu_type:
          type: string
          description: GPU model.
          example: RTX 4090
        size:
          type: string
          description: |
            Headline shape of the instance, as a count and a unit rather than a
            preset name. Use `GET /presets` to resolve the full hardware.
          example: 8 x GPU
        cpu_count:
          type: integer
          description: Virtual CPUs allocated.
        resources:
          type: string
          description: Human-readable summary of the allocated hardware.
        bandwidth:
          type: number
          description: Allocated bandwidth, in Mbps.
        storage_used_gb:
          type: number
          description: Disk provisioned for the instance, in GB. Not a measure of use.
        hourly_rate:
          type: number
          description: Price charged per hour while running, in credits.
        current_cost:
          type: number
          description: |
            Total spend accrued over the instance's life, in credits. Currently
            identical to `total_cost_incurred`; it is not scoped to the current
            run.
        total_cost_incurred:
          type: number
          description: Total cost over the instance's whole life, in credits.
        total_runtime_hours:
          type: number
          description: Total hours the instance has spent running.
        ttl_remaining_hours:
          type: number
          description: |
            Credit runway in hours, computed across the whole organisation
            rather than for this instance, so every instance in an org reports
            the same figure.
        started_at:
          type: string
          format: date-time
          nullable: true
          description: When the instance last entered `RUNNING`.
        terminated_at:
          type: string
          format: date-time
          nullable: true
          description: When the instance was terminated, if it has been.
        termination_reason:
          type: string
          nullable: true
          enum:
            - USER_INITIATED
            - CREDIT_EXHAUSTION
            - UNKNOWN
            - null
          description: |
            Why the instance is being or was terminated: `USER_INITIATED` for a
            terminate call, `CREDIT_EXHAUSTION` when the organisation ran out of
            credits, `UNKNOWN` when the platform cannot tell (an instance that
            failed is reported this way). `null` until the instance is
            `TERMINATING` or `TERMINATED`.
        guest_ready:
          type: string
          enum:
            - READY
            - DEGRADED
            - UNKNOWN
          description: |
            Whether the guest OS inside a VM has booted and answers its agent:
            `READY` when it does, `DEGRADED` when the VM is up but the agent is
            silent, `UNKNOWN` when nothing has reported (always the case for
            containers). Informational only: it never changes `status` or
            billing.
        guest_ready_reason:
          type: string
          nullable: true
          description: Explanation when the guest is not ready.
  responses:
    ValidationError:
      description: The request was malformed or a parameter was invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: VALIDATION_ERROR
              message: >-
                [{"property":"size","constraints":["size must not be greater
                than 200"]}]
              request_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
    Unauthorized:
      description: The API key is missing, malformed or not valid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: UNAUTHORIZED
              message: Missing API token
              request_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
    RateLimited:
      description: |
        Too many requests. Wait the number of seconds given in `Retry-After`
        before retrying.
      headers:
        Retry-After:
          description: Seconds to wait before retrying.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: TOO_MANY_REQUESTS
              message: Too Many Requests
              request_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
    CreateOutcomeUnknown:
      description: |
        The create may or may not have happened: the instance can exist and
        be billing even though no id was returned. Do not retry blindly. List
        your instances with `GET /instances`, and create again only if the
        instance is not there.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: |
        An API key issued by Hive Compute support. See **Authentication**
        above for how to request one.

````

## Related topics

- [Create an instance](https://docs.hivenet.com/api-reference/instances/create-an-instance.md)
- [Launch and connect to your first Compute instance](https://docs.hivenet.com/documentation/essentials/create-instance.md)
- [Changelog](https://docs.hivenet.com/changelog.md)
- [How organizations work in Compute](https://docs.hivenet.com/documentation/organizations/how-organizations-work.md)
- [API changelog](https://docs.hivenet.com/public-api/api-changelog.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.