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.
curl --request POST \
--url https://api.hivecompute.ai/v1/instances \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "training-run-1",
"preset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_id": "ubuntu24.04"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'training-run-1',
preset_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
image_id: 'ubuntu24.04'
})
};
fetch('https://api.hivecompute.ai/v1/instances', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.hivecompute.ai/v1/instances"
payload = {
"name": "training-run-1",
"preset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_id": "ubuntu24.04"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"instance": {
"instance_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "training-run-4",
"status": "CREATED",
"region": "france-2",
"gpu_type": "RTX 4090",
"size": "8 x GPU",
"cpu_count": 123,
"resources": "<string>",
"bandwidth": 123,
"storage_used_gb": 123,
"hourly_rate": 123,
"current_cost": 123,
"total_cost_incurred": 123,
"total_runtime_hours": 123,
"ttl_remaining_hours": 123,
"started_at": "2023-11-07T05:31:56Z",
"terminated_at": "2023-11-07T05:31:56Z",
"termination_reason": "USER_INITIATED",
"guest_ready": "READY",
"guest_ready_reason": "<string>"
}
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "[{\"property\":\"size\",\"constraints\":[\"size must not be greater than 200\"]}]",
"request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing API token",
"request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "TOO_MANY_REQUESTS",
"message": "Too Many Requests",
"request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}Before you send the request
Choose a preset from List presets and an image from List images. The preset determines the hardware and location. Matchimage_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. |
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"
}'
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 returns201 Created. Read instance.instance_id from the response. If instance contains only instance_id, creation still succeeded. Poll Get instance 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. |
409 does not include Retry-After. Choose another compatible preset or try again later.
500, 503, or 504, check List instances before you submit again.PATCH.Authorizations
Body
Was this page helpful?
curl --request POST \
--url https://api.hivecompute.ai/v1/instances \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "training-run-1",
"preset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_id": "ubuntu24.04"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'training-run-1',
preset_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
image_id: 'ubuntu24.04'
})
};
fetch('https://api.hivecompute.ai/v1/instances', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.hivecompute.ai/v1/instances"
payload = {
"name": "training-run-1",
"preset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_id": "ubuntu24.04"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"instance": {
"instance_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "training-run-4",
"status": "CREATED",
"region": "france-2",
"gpu_type": "RTX 4090",
"size": "8 x GPU",
"cpu_count": 123,
"resources": "<string>",
"bandwidth": 123,
"storage_used_gb": 123,
"hourly_rate": 123,
"current_cost": 123,
"total_cost_incurred": 123,
"total_runtime_hours": 123,
"ttl_remaining_hours": 123,
"started_at": "2023-11-07T05:31:56Z",
"terminated_at": "2023-11-07T05:31:56Z",
"termination_reason": "USER_INITIATED",
"guest_ready": "READY",
"guest_ready_reason": "<string>"
}
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "[{\"property\":\"size\",\"constraints\":[\"size must not be greater than 200\"]}]",
"request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing API token",
"request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "TOO_MANY_REQUESTS",
"message": "Too Many Requests",
"request_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "<string>",
"request_id": "<string>"
}
}