> ## 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 an instance using the Compute API

> Provision a Compute VM or container: choose a region, preset, and image, register an SSH public key, create the instance, and check its state.

Use the Compute API to create a VM or container from a hardware preset and image. This guide takes you from catalogue selection to a running instance.

## Before you start

You need a Compute account, a [Compute API key](https://docs.hivenet.com/public-api/authenticate-api-requests.md), a terminal with `curl`, and an SSH key pair. Set `HIVENET_API_KEY` securely in your environment.

For a prepaid account, make sure the balance covers one hour of the selected preset.

> [!WARNING]
>
> Creating an instance can incur charges. Review the preset's price before submitting the create request. Only upload your SSH public key; keep the private key on your machine.

The examples use the production base URL, `https://api.hivecompute.ai/v1`. Replace every `YOUR_...` placeholder before sending a request.

## 1. Choose a region and preset

List region codes:

```bash theme={null}
curl --request GET \
  --url "https://api.hivecompute.ai/v1/regions" \
  --header "Authorization: Bearer $HIVENET_API_KEY" \
  --header "Accept: application/json"
```

Use a returned region code to list presets. This example uses `FR`:

```bash theme={null}
curl --request GET \
  --url "https://api.hivecompute.ai/v1/presets?region=FR&size=200" \
  --header "Authorization: Bearer $HIVENET_API_KEY" \
  --header "Accept: application/json"
```

Check the preset's location, CPU, memory, storage, GPU count, and price. Follow [pagination](https://docs.hivenet.com/public-api/use-pagination-and-filters.md) if `pagination.next` is not `null`. Look up the preset again before each create. A preset can be retired or its size and price can change.

Preset `cpu`, `memory`, and `storage` are numeric strings without units. `hourly_price` and `price_discounted` are decimal strings; an empty `price_discounted` means no preset discount. Convert strings explicitly when comparing values. Do not treat an empty discount as a zero price.

## 2. Choose an image

For a VM:

```bash theme={null}
curl --request GET \
  --url "https://api.hivecompute.ai/v1/images?type=vm" \
  --header "Authorization: Bearer $HIVENET_API_KEY" \
  --header "Accept: application/json"
```

For a container, use `type=container` and follow `pagination.next` if another page is available. Select an image compatible with the preset. A GPU VM needs `gpu_supported: true`. Check the minimum memory and disk size and save the image’s `id`.

The image endpoint does not filter by region. Some VM minimum-size fields are zero in this release; do not interpret zero as a sizing recommendation.

## 3. Register your SSH public key

New instances use the public key you registered most recently in the API or console. If that is the key you want, skip to step 4. To use another key for future instances, create a local `ssh-key.json` file.

```json theme={null}
{
  "content": "YOUR_SSH_PUBLIC_KEY"
}
```

Replace the placeholder with the complete single-line public key from your `.pub` file, then send it:

```bash theme={null}
curl --request POST \
  --url "https://api.hivecompute.ai/v1/ssh-keys" \
  --header "Authorization: Bearer $HIVENET_API_KEY" \
  --header "Content-Type: application/json" \
  --data-binary @ssh-key.json
```

Expect `201 Created`. Save the returned key `id`; [Get SSH key](https://docs.hivenet.com/public-api/endpoints/get-ssh-key.md) lets you retrieve it later. Repeating registration creates a new record, even for identical key content.

## 4. Create the instance

> [!WARNING]
>
> Each successful request creates a separately billed instance. Names can repeat. If the connection drops or you receive `500`, `503`, or `504`, list your instances and check whether creation succeeded before retrying.

```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"
  }'
```

Use the IDs selected in steps 1 and 2. For a container, set `image_type` to `container` and use a container image ID. The minimal request above uses the account's registered SSH key without a key-selection field.

Expect `201 Created` and save `instance.instance_id`. If the response contains only that ID inside `instance`, creation succeeded. Use it in the next step. When available, `hourly_rate` on the instance is the billed rate in credits per hour, returned as a JSON number.

If creation returns `409 CONFLICT`, check credit, capacity, and whether the preset changed during the request. A no-capacity response does not include `Retry-After`. Choose another compatible preset or try later.

## 5. Check readiness and connect

Poll the instance:

```bash theme={null}
curl --request GET \
  --url "https://api.hivecompute.ai/v1/instances/YOUR_INSTANCE_ID" \
  --header "Authorization: Bearer $HIVENET_API_KEY" \
  --header "Accept: application/json"
```

Allow time between requests and stay below [60 requests per minute per API key and endpoint](https://docs.hivenet.com/public-api/handle-errors-and-rate-limits.md). Continue until `status` is `RUNNING`. Applications inside the instance may still be starting.

If the instance reaches `ERRORED`, inspect its [logs](https://docs.hivenet.com/public-api/endpoints/get-instance-logs.md) and console details before trying another creation.

Open the instance in the Compute console and use the connection command shown there. Keep any supplied host, port, and connection options.

## Manage the instance

Use [Work with instances](https://docs.hivenet.com/public-api/work-with-instances.md) to stop, restart, read logs and metrics, or terminate it.

> [!CAUTION]
>
> Termination permanently deletes the instance and its data. Use stop if you need to keep the instance for later.


## Related topics

- [Create instance](https://docs.hivenet.com/public-api/endpoints/create-instance.md)
- [Work with instances](https://docs.hivenet.com/public-api/work-with-instances.md)
- [How to start and stop your Compute instances](https://docs.hivenet.com/documentation/essentials/start-stop-instances.md)
- [Get started with the Compute API](https://docs.hivenet.com/public-api/get-started-with-the-compute-api.md)
- [Compute quickstart](https://docs.hivenet.com/quickstart.md)


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