SDKs: GraphQL Templates

Manage Templates using the Tensor One GraphQL API. This guide covers how to create, update, and delete both GPU and Serverless templates.

Required Template Arguments

When creating a Template, make sure to include the following required fields:
  • containerDiskInGb - Container disk size (GB)
  • dockerArgs - Custom start command
  • env - Environment variables (key-value pairs)
  • imageName - Docker image to launch
  • name - Unique template name
  • volumeInGb - Persistent volume size (GB)
Note: Template names must be unique. Attempts to reuse a name will fail. For private container images, include:
  • containerRegistryAuthId: The ID (not name) of saved registry credentials (see user settings)

Creating Templates

Create GPU Template

curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.tensorone.ai/graphql?api_key=${YOUR_API_KEY}' \
--data '{
  "query": "mutation {
    saveTemplate(input: {
      containerDiskInGb: 5,
      dockerArgs: \"sleep infinity\",
      env: [
        { key: \"key1\", value: \"value1\" },
        { key: \"key2\", value: \"value2\" }
      ],
      imageName: \"ubuntu:latest\",
      name: \"Generated Template\",
      ports: \"8888/http,22/tcp\",
      readme: \"## Hello, World!\",
      volumeInGb: 15,
      volumeMountPath: \"/workspace\"
    }) {
      containerDiskInGb dockerArgs env { key value } id imageName name ports readme volumeInGb volumeMountPath
    }
  }"
}'

Create Serverless Template

Always set volumeInGb: 0 for serverless templates:
curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.tensorone.ai/graphql?api_key=${YOUR_API_KEY}' \
--data '{
  "query": "mutation {
    saveTemplate(input: {
      containerDiskInGb: 5,
      dockerArgs: \"python handler.py\",
      env: [
        { key: \"key1\", value: \"value1\" },
        { key: \"key2\", value: \"value2\" }
      ],
      imageName: \"tensorone/serverless-hello-world:latest\",
      isServerless: true,
      name: \"Generated Serverless Template\",
      readme: \"## Hello, World!\",
      volumeInGb: 0
    }) {
      containerDiskInGb dockerArgs env { key value } id imageName isServerless name readme
    }
  }"
}'

Modifying Templates

Modify GPU Pod Template

curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.tensorone.ai/graphql?api_key=${YOUR_API_KEY}' \
--data '{
  "query": "mutation {
    saveTemplate(input: {
      id: \"wphkv67a0p\",
      containerDiskInGb: 5,
      dockerArgs: \"sleep infinity\",
      env: [
        { key: \"key1\", value: \"value1\" },
        { key: \"key2\", value: \"value2\" }
      ],
      imageName: \"ubuntu:latest\",
      name: \"Generated Template\",
      volumeInGb: 15,
      readme: \"## Goodbye, World!\"
    }) {
      id containerDiskInGb dockerArgs env { key value } imageName name volumeInGb readme
    }
  }"
}'

Modify Serverless Template

curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.tensorone.ai/graphql?api_key=${YOUR_API_KEY}' \
--data '{
  "query": "mutation {
    saveTemplate(input: {
      id: \"xkhgg72fuo\",
      containerDiskInGb: 5,
      dockerArgs: \"python handler.py\",
      env: [
        { key: \"key1\", value: \"value1\" },
        { key: \"key2\", value: \"value2\" }
      ],
      imageName: \"tensorone/serverless-hello-world:latest\",
      name: \"Generated Serverless Template\",
      volumeInGb: 0,
      readme: \"## Goodbye, World!\"
    }) {
      id containerDiskInGb dockerArgs env { key value } imageName name readme
    }
  }"
}'

Deleting Templates

Note: Templates cannot be deleted if they are actively in use. After recent usage, allow up to 2 minutes before attempting deletion.
curl --request POST \
--header 'content-type: application/json' \
--url 'https://api.tensorone.ai/graphql?api_key=${YOUR_API_KEY}' \
--data '{
  "query": "mutation {
    deleteTemplate(templateName: \"Generated Template\")
  }"
}'