---
title: "Create a template"
method: POST
path: "/v1/templates"
tags: ["Templates"]
---

# Create a template

`POST /v1/templates`

## Request

- Base URL: `https://docs.grepr.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://docs.grepr.ai/v1/templates`
- Auth: one of:
  - API key in header `GREPR-API-KEY`
  - OpenID Connect (`https://grepr-prod.us.auth0.com/.well-known/openid-configuration`)

Creates a new template for generating job subgraphs.

## Request body

- Template: A reusable template for generating a subgraph of a Grepr job graph using Javascript. Templates allow users to define parameterized pipeline components that can be instantiated with specific configuration.
  - `builtIn` boolean: Read-only property indicating whether this template is a built-in, non-editable template.
  - `description` string: Description of the template.
  - `draftOutputs` TemplateDraftOutput[]: List of additional outputs that will be added to the graph when running in draft mode.
    - `name` string: Name of the draft output.
    - `tagKey` string: Tag key that will be added to the draft output.
    - `tagValue` string: Tag value that will be added to the draft output.
  - `id` string: Unique identifier for the template.
  - `inputSchema` object: JSONSchema (https://json-schema.org/draft/2020-12) for validating the inputs to the template. Make sure you make this validation forwards/backwards compatible to ensure that the template version can be upgraded and rolled back.
  - `inputs` object: Map of input names used in a parent subgraph that uses a TemplateOperation to their internal connections within the subgraph. Can be missing if there are no inputs to the subgraph
  - `isLatest` boolean
  - `latest` boolean
  - `name` string, required: Name of the template.
  - `organizationId` string: Organization ID to which the template belongs. This is null for built-in templates.
  - `outputs` object: Map of output names used in a parent subgraph that uses a TemplateOperation to their internal connections within the subgraph. Can be missing if there are no outputs from the subgraph
  - `sourceHash` string: SHA-256 hash of template source and all dependencies (utils, types, build config, package versions). Used to track when template dependencies change and avoid unnecessary updates.
  - `teamIds` string[]: Set of team IDs that can use this template.
  - `template` string, required: A javascript string that generates the JSON for the job subgraph. It will receive as input a User object and the inputs provided via the operation when it is getting resolved into a subgraph.
  - `version` integer, required: Version of the template.

## Response `200`

Template created successfully

## Other responses

- `400`: Invalid template data
- `401`: Unauthorized

---

[API](https://skmtc.dev/grepr/apis/grepr-api.md) - [All operations](https://skmtc.dev/grepr/apis/grepr-api/llms.txt) - [OpenAPI document](https://skmtc.dev/grepr/apis/grepr-api/revisions/2a5ce03a0bf0?raw)
