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

# Create a new template

`POST /v1/templates`

## Request

- Base URL: `https://api.lunary.ai`
- URL: `https://api.lunary.ai/v1/templates`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/lunary/apis/lunary-api/docs/v1/templates/post.ts> (a function with typed inputs; its response is checked against the schema)

Creates a new template with the provided details.
The template includes a slug, mode, content, and additional configuration options.

## Request body

- TemplateInput
  - `slug` string, required
  - `mode` 'text' | 'openai', required
  - `content` object[], required
    - `role` string
    - `content` string
  - `metadata` PromptMetadata: Versioned key/value text, separate from model parameters and prompt variables. Keys are preserved exactly, must not be blank, and are limited to 256 characters. The reserved key __proto__ is not allowed. Values must be strings. Numbers, booleans, null, arrays, and objects are rejected. The serialized object must be no larger than 64 KiB. Returned by prompt retrieval endpoints, including public-key retrieval; do not store secrets here. Omitted metadata defaults to an empty object on creation and is preserved on PATCH.
  - `extra` object
  - `testValues` object
  - `isDraft` boolean
  - `notes` string

## Response `200`

Successful response

- Template
  - `id` string
  - `name` string
  - `slug` string
  - `mode` 'text' | 'openai'
  - `createdAt` string, date-time
  - `group` string
  - `projectId` string
  - `versions` TemplateVersion[]
    - `id` string
    - `templateId` string
    - `content` object[]
      - `role` string
      - `content` string
    - `metadata` PromptMetadata: Versioned key/value text, separate from model parameters and prompt variables. Keys are preserved exactly, must not be blank, and are limited to 256 characters. The reserved key __proto__ is not allowed. Values must be strings. Numbers, booleans, null, arrays, and objects are rejected. The serialized object must be no larger than 64 KiB. Returned by prompt retrieval endpoints, including public-key retrieval; do not store secrets here. Omitted metadata defaults to an empty object on creation and is preserved on PATCH.
    - `extra` object
    - `testValues` object
    - `isDraft` boolean
    - `notes` string
    - `createdAt` string, date-time
    - `version` number

---

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