# Create a template

> Create a workspace template, blank or from a document.

<Endpoint method="POST" path="/v1/templates" />

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/templates \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Product card", "external_id": "product-card", "tags": ["shop"] }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "Product card",
    external_id: "product-card",
    tags: ["shop"],
  }),
});
const template = await res.json();
```

```python tab="Python"
import os
import requests

template = requests.post(
    "https://api.muzekit.com/v1/templates",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={"name": "Product card", "external_id": "product-card", "tags": ["shop"]},
).json()
```

</CodeTabs>

## Body

<ParamTable params={[
  { name: "name", type: "string", required: true, description: "Up to 200 characters." },
  { name: "description", type: "string", description: "Up to 2,000 characters." },
  { name: "tags", type: "string[]", description: "Up to 30 tags." },
  { name: "external_id", type: "string", description: "The template's key: the same in every environment, accepted wherever a tpl_ id is. Made from the name when you leave it out. Lowercase letters, numbers, dots, dashes and underscores." },
  { name: "document", type: "object", description: "A document (see Templates). Without one, a blank 1080 × 1080 page." }
]} />

Returns the [template](/docs/api-reference/templates-list) with `201`. A document that breaks a rule returns `400 invalid_document` with every problem in `problems`. A key another template in this environment already has returns `409 external_id_taken`.

## Examples

### Create from a saved document

Send a [document](/docs/templates#documents) you keep in your own code, or one you read from another template with [Get a document](/docs/api-reference/templates-document-get). Give it a key so your code can name it the same way in Test and Live.

<CodeTabs>

```bash tab="cURL"
# product-card.json holds the document: { "pages": [ … ] }
jq '{ name: "Product card", external_id: "product-card", document: . }' \
  product-card.json \
  | curl https://api.muzekit.com/v1/templates \
    -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
    -H "Content-Type: application/json" \
    -d @-
```

```javascript tab="Node"
import { readFile } from "node:fs/promises";

const document = JSON.parse(await readFile("product-card.json", "utf8"));

const res = await fetch("https://api.muzekit.com/v1/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "Product card",
    external_id: "product-card",
    document,
  }),
});
const template = await res.json();
```

```python tab="Python"
import json
import os
import requests

with open("product-card.json") as f:
    document = json.load(f)

template = requests.post(
    "https://api.muzekit.com/v1/templates",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={
        "name": "Product card",
        "external_id": "product-card",
        "document": document,
    },
).json()
```

</CodeTabs>

### Create a blank template at another size

For a size other than 1080 × 1080, send a document with one empty page of that size. Your team or your users then design it in the editor.

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/templates \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Story",
    "external_id": "story",
    "document": {
      "pages": [
        { "id": "page-1", "canvas": { "width": 1080, "height": 1920 }, "elements": [] }
      ]
    }
  }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "Story",
    external_id: "story",
    document: {
      pages: [
        { id: "page-1", canvas: { width: 1080, height: 1920 }, elements: [] },
      ],
    },
  }),
});
const template = await res.json();
```

```python tab="Python"
import os
import requests

template = requests.post(
    "https://api.muzekit.com/v1/templates",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={
        "name": "Story",
        "external_id": "story",
        "document": {
            "pages": [
                {"id": "page-1", "canvas": {"width": 1080, "height": 1920}, "elements": []}
            ]
        },
    },
).json()
```

</CodeTabs>

### Retry without making two templates

Send an `Idempotency-Key`. If the network drops and you send the same request again within 24 hours, you get the first response back instead of a second template.

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/templates \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: create-product-card-1" \
  -d '{ "name": "Product card", "external_id": "product-card" }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "create-product-card-1",
  },
  body: JSON.stringify({ name: "Product card", external_id: "product-card" }),
});
const template = await res.json();
```

```python tab="Python"
import os
import requests

template = requests.post(
    "https://api.muzekit.com/v1/templates",
    headers={
        "Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}",
        "Idempotency-Key": "create-product-card-1",
    },
    json={"name": "Product card", "external_id": "product-card"},
).json()
```

</CodeTabs>

## Response

A new template has no `thumbnail_url` until the editor saves it.

```json
{
  "object": "template",
  "id": "tpl_Vk1t4l9xvQv",
  "name": "Product card",
  "description": null,
  "tags": ["shop"],
  "external_id": "product-card",
  "user": null,
  "source": "api",
  "version": { "id": "ver_…", "number": 1, "revision": 1 },
  "width": 1080,
  "height": 1080,
  "page_count": 1,
  "thumbnail_url": null,
  "created_at": "2026-10-17T02:10:00.000Z",
  "updated_at": "2026-10-17T02:10:00.000Z"
}
```
