Skip to main content
Use the GraphQL API to create and manage templates for Pods and Serverless endpoints. For the complete schema, see the GraphQL Spec.

Quick reference

OperationMutation
Create templatesaveTemplate
Modify templatesaveTemplate (with id)
Delete templatedeleteTemplate
Create secretsecretCreate
Delete secretsecretDelete

Required fields

Templates require the following fields:
FieldTypeDescription
containerDiskInGbIntegerContainer disk size in GB.
imageNameStringDocker image name with tag (e.g., ubuntu:latest).
nameStringUnique template name.
volumeInGbIntegerVolume size in GB. Set to 0 for Serverless templates.
Template names must be unique. Creating a template with a name that already exists will fail.

Create a template

GPU Pod template

curl --request POST \
  --header 'content-type: application/json' \
  --url 'https://api.runpod.io/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: \"My GPU 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 } }"}'

Serverless template

For Serverless templates, set volumeInGb to 0 and include isServerless: true.
curl --request POST \
  --header 'content-type: application/json' \
  --url 'https://api.runpod.io/graphql?api_key=${YOUR_API_KEY}' \
  --data '{"query": "mutation { saveTemplate(input: { containerDiskInGb: 5, dockerArgs: \"python handler.py\", env: [ { key: \"key1\", value: \"value1\" } ], imageName: \"runpod/serverless-hello-world:latest\", isServerless: true, name: \"My Serverless Template\", volumeInGb: 0 }) { id name imageName isServerless containerDiskInGb } }"}'

Private container images

For private container images, use containerRegistryAuthId with the ID of your saved registry credentials from your Runpod settings.
mutation {
  saveTemplate(input: {
    containerDiskInGb: 5,
    imageName: "myregistry.io/private-image:latest",
    containerRegistryAuthId: "YOUR_REGISTRY_CREDENTIALS_ID",
    name: "Private Image Template",
    volumeInGb: 10
  }) {
    id
    name
  }
}

Modify a template

Include the template id to update an existing template. The same mutation works for both GPU and Serverless templates.
curl --request POST \
  --header 'content-type: application/json' \
  --url 'https://api.runpod.io/graphql?api_key=${YOUR_API_KEY}' \
  --data '{"query": "mutation { saveTemplate(input: { id: \"wphkv67a0p\", containerDiskInGb: 10, imageName: \"ubuntu:latest\", name: \"My GPU Template\", volumeInGb: 20, readme: \"## Updated readme\" }) { id containerDiskInGb volumeInGb readme } }"}'

Delete a template

Delete a template by name. The template must not be in use by any Pods or Serverless endpoints.
It can take up to 2 minutes to delete a template after its most recent use by a Pod or Serverless endpoint.
curl --request POST \
  --header 'content-type: application/json' \
  --url 'https://api.runpod.io/graphql?api_key=${YOUR_API_KEY}' \
  --data '{"query": "mutation { deleteTemplate(templateName: \"My GPU Template\") }"}'

Create a secret

Secrets store sensitive values that can be referenced in templates.
curl --request POST \
  --header 'content-type: application/json' \
  --url 'https://api.runpod.io/graphql?api_key=${YOUR_API_KEY}' \
  --data '{"query": "mutation { secretCreate(input: { value: \"my-secret-value\", name: \"my-secret\" }) { id name description } }"}'

Delete a secret

Delete a secret by its ID. You can find the secret ID from the secretCreate response or by querying your secrets.
curl --request POST \
  --header 'content-type: application/json' \
  --url 'https://api.runpod.io/graphql?api_key=${YOUR_API_KEY}' \
  --data '{"query": "mutation { secretDelete(id: \"abc123\") }"}'