# Templates

> Workspace templates, user templates, documents and versions.

## Two kinds

- **Workspace templates** are made by your team in the dashboard or by your server through the API. `GET /v1/templates` lists them.
- **User templates** belong to one end user, made in their sessions. `GET /v1/templates?user=usr_…` lists one user's templates.

<Screenshot src="/docs/1-templates-library.webp" original="/docs/raw/1-templates-library.png" alt="Templates in the dashboard, Library tab with the Picked filter: the ready-made image, carousel and video templates your users see in the editor, searchable by category" />

## Template keys

Every workspace template has a **key**, its `external_id`: made from its name when the template is created (`summer-sale-post`), or the one you set. The key is the same in Test and Live, and Copy to Live carries it across, so your code can name a template by its key everywhere you'd use its `tpl_…` id: opening a session (`template`), rendering, and `/v1/templates/{key}`. The `tpl_…` id is different in each environment.

A key is up to 100 lowercase letters, numbers, dots, dashes and underscores, starting with a letter or number, and never `tpl_…`. Change one in the dashboard (Templates, the pencil) or with [Update a template](/docs/api-reference/templates-update). Copy to Live matches templates by key, so change it in Test and Live.

## Previews

Templates carry `thumbnail_url`: their first page as the editor last saved it, or `null` for a template only ever written through the API. The file at a URL never changes, so cache it as long as you like; a newer save gives a new URL.

## Documents

A template's content is a **document**: pages, each with a canvas size and elements. Read it with `GET /v1/templates/{id}/document`; the response carries a `revision` number.

```json
{
  "schema": { "core": 1 },
  "pages": [
    {
      "id": "page-1",
      "canvas": { "width": 1080, "height": 1080 },
      "elements": []
    }
  ],
  "meta": {},
  "ext": {}
}
```

Documents are checked strictly: at most 100 pages, 500 elements per page and 5 MB, and no `data:` URLs except small plain-text SVGs (up to 16 KB, not base64), which icons and shapes use. Upload other files as assets.

## Saving

Saving updates the current version in place. Send the revision you edited in `If-Match`; if the document changed since, you get `409 revision_conflict`, so two editors never overwrite each other silently.

```bash
curl -X PUT https://api.muzekit.com/v1/templates/tpl_…/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H 'If-Match: "3"' \
  -H "Content-Type: application/json" \
  -d '{ "document": { "pages": [ … ] } }'
```
