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

# GraphQL Templates Management

> Complete GraphQL API guide for managing Tensor One templates including creating GPU and serverless templates, modifications, deletions, and required field specifications with curl examples.

***

## 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

```bash
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:

```bash
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

```bash
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

```bash
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.

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


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