Skip to main content
POST
/
preview
/
v2
/
instance_templates
Create instance template
curl --request POST \
  --url https://api.sfcompute.com/preview/v2/instance_templates \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "workspace": "<string>",
  "image": "<string>",
  "name": "my-resource-name",
  "tags": {
    "env": "prod",
    "team": "infra"
  },
  "cloud_init_user_data": "IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="
}
'
import requests

url = "https://api.sfcompute.com/preview/v2/instance_templates"

payload = {
"workspace": "<string>",
"image": "<string>",
"name": "my-resource-name",
"tags": {
"env": "prod",
"team": "infra"
},
"cloud_init_user_data": "IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
workspace: '<string>',
image: '<string>',
name: 'my-resource-name',
tags: {env: 'prod', team: 'infra'},
cloud_init_user_data: 'IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo='
})
};

fetch('https://api.sfcompute.com/preview/v2/instance_templates', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sfcompute.com/preview/v2/instance_templates",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'workspace' => '<string>',
'image' => '<string>',
'name' => 'my-resource-name',
'tags' => [
'env' => 'prod',
'team' => 'infra'
],
'cloud_init_user_data' => 'IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo='
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.sfcompute.com/preview/v2/instance_templates"

payload := strings.NewReader("{\n \"workspace\": \"<string>\",\n \"image\": \"<string>\",\n \"name\": \"my-resource-name\",\n \"tags\": {\n \"env\": \"prod\",\n \"team\": \"infra\"\n },\n \"cloud_init_user_data\": \"IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo=\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.sfcompute.com/preview/v2/instance_templates")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"workspace\": \"<string>\",\n \"image\": \"<string>\",\n \"name\": \"my-resource-name\",\n \"tags\": {\n \"env\": \"prod\",\n \"team\": \"infra\"\n },\n \"cloud_init_user_data\": \"IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo=\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.sfcompute.com/preview/v2/instance_templates")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"workspace\": \"<string>\",\n \"image\": \"<string>\",\n \"name\": \"my-resource-name\",\n \"tags\": {\n \"env\": \"prod\",\n \"team\": \"infra\"\n },\n \"cloud_init_user_data\": \"IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo=\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "itmpl_k3R-nX9vLm7Qp2Yw5Jd8F",
  "resource_path": "<string>",
  "owner": "<string>",
  "workspace": "<string>",
  "workspace_id": "<string>",
  "name": "<string>",
  "object": "instance_template",
  "image": {
    "id": "image_k3R-nX9vLm7Qp2Yw5Jd8F",
    "name": "<string>"
  },
  "cloud_init_user_data_used": true,
  "created_at": 1738972800,
  "tags": {
    "env": "prod",
    "team": "infra"
  },
  "cloud_init_user_data": "IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="
}
{
"error": {
"type": "authentication_error",
"message": "<string>"
}
}
{
"error": {
"type": "forbidden",
"message": "<string>"
}
}
{
"error": {
"type": "unprocessable_entity",
"message": "<string>",
"details": [
{
"code": "<string>",
"message": "<string>",
"field": "<string>"
}
]
}
}
{
"error": {
"type": "api_error",
"message": "<string>"
}
}

Authorizations

Authorization
string
header
required

Create an API token using sf tokens create or at https://sfcompute.com/account/api-keys.

Body

application/json
workspace
string
required

Workspace to create this template in.

Pattern: (wksp_[0-9a-zA-Z_-]{1,21})|(sfc:workspace:[a-zA-Z0-9._-]+(:[a-zA-Z0-9._-]+){1,1})
Example:

"wksp_k3R-nX9vLm7Qp2Yw5Jd8F"

image
string
required

Machine image to use when starting instances with this template. Accepts name or ID.

Pattern: (image_[0-9a-zA-Z_-]{1,21}|vmi_[0-9a-zA-Z_-]{1,21})|(sfc:image:[a-zA-Z0-9._-]+(:[a-zA-Z0-9._-]+){2,2})
Example:

"image_k3R-nX9vLm7Qp2Yw5Jd8F"

name
null | string
Required string length: 1 - 255
Pattern: [a-zA-Z0-9][a-zA-Z0-9._-]{0,254}
Example:

"my-resource-name"

tags
null | object

Metadata tags to attach to this instance template.

Example:
{ "env": "prod", "team": "infra" }
cloud_init_user_data
string<byte>

Base64-encoded cloud-init user data. Maximum 64KB.

Example:

"IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="

Response

Instance template created.

id
required

Accepts the canonical prefix below; additional legacy prefixes are aliased for read compatibility. Writes always emit the canonical form.

Pattern: itmpl_[0-9a-zA-Z_-]{1,21}
Example:

"itmpl_k3R-nX9vLm7Qp2Yw5Jd8F"

resource_path
string
required

A resource path for a instance_template resource. Format: sfc:instance_template:::.

Pattern: sfc:instance_template:([a-zA-Z0-9._-]+:){2}[a-zA-Z0-9._-]+
Example:

"sfc:instance_template:<account_id>:<workspace>:<name>"

owner
string
required
Required string length: 1 - 255
Pattern: [a-zA-Z0-9][a-zA-Z0-9._-]{0,254}
Example:

"my-resource-name"

workspace
string
required
Required string length: 1 - 255
Pattern: [a-zA-Z0-9][a-zA-Z0-9._-]{0,254}
Example:

"my-resource-name"

workspace_id
string
required
Pattern: wksp_[0-9a-zA-Z_-]{1,21}
Example:

"wksp_k3R-nX9vLm7Qp2Yw5Jd8F"

name
string
required
Required string length: 1 - 255
Pattern: [a-zA-Z0-9][a-zA-Z0-9._-]{0,254}
Example:

"my-resource-name"

object
string
default:instance_template
required
read-only
Allowed value: "instance_template"
image
object
required

Machine image to use when starting instances with this template.

cloud_init_user_data_used
boolean
required

Whether cloud-init user data is configured for this template.

created_at
integer<int64>
required

Unix timestamp.

Example:

1738972800

tags
null | object

Metadata tags attached to this instance template.

Example:
{ "env": "prod", "team": "infra" }
cloud_init_user_data
string<byte>

Base64-encoded cloud-init user data.

Example:

"IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="