# Create an embedded editor session (/docs/api-reference/embedded-editor/create)

> Lets one of your users edit one template inside your product, in Druckling's white-label editor.

`POST https://druckling-nine.vercel.app/v1/embed_sessions`

Lets one of your users edit one template inside your product, in Druckling's white-label editor. Call this from your backend with a full-access key (`templates:write`) when the user opens the editor, then give the returned `url` to their browser.

The editor loads in an iframe on the origins allowed in Settings › Embed (enforced with CSP `frame-ancestors`); without any allowed origin the answer is 409 `invalid_state`. The session can read that template, save its draft, render previews and, if you allow it, publish. Nothing else in the workspace (other templates, documents, API keys, webhooks, billing, team) is reachable with it.

Sessions are short-lived: 30 minutes by default, at most an hour. When one expires the editor tells your page with an `error` event (`session_expired`); create a new session to continue. Drafts are saved continuously, so nothing is lost. The editor shows a small "Powered by Druckling" mark on the Free and Starter plans.

## Request body (JSON Schema)

```json
{
  "type": "object",
  "properties": {
    "template": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "Slug of the template to edit, e.g. invoice-standard."
    },
    "permissions": {
      "type": "object",
      "properties": {
        "publish": {
          "type": "boolean",
          "description": "Let the user publish new versions (default false: the user edits the draft, you publish)."
        },
        "assistant": {
          "type": "boolean",
          "description": "Offer the AI assistant, on plans that include it (Pro, Business). Default false."
        }
      }
    },
    "expires_in": {
      "type": "integer",
      "minimum": 60,
      "maximum": 3600,
      "description": "Seconds until the session ends: default 1800, at most 3600."
    },
    "user": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "description": "Your id for the user."
        },
        "name": {
          "type": "string",
          "maxLength": 200
        }
      },
      "required": [
        "id"
      ],
      "description": "Who is editing. Shown in Druckling's request logs and on the versions they publish (`embed:<id>`)."
    },
    "theme": {
      "type": "object",
      "properties": {
        "mode": {
          "enum": [
            "light",
            "dark",
            "system"
          ],
          "type": "string",
          "description": "Default `light`. `system` follows the user's OS setting."
        },
        "accent": {
          "type": "string",
          "pattern": "^#(?:[0-9a-fA-F]{3}){1,2}$",
          "description": "Your brand color for buttons and highlights, e.g. `#0f766e`."
        }
      }
    }
  },
  "required": [
    "template"
  ]
}
```

## Response 201: OK

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "const": "embed_session"
    },
    "url": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Load this URL in an iframe (or pass it to `mountEditor` from `@druckling/embed`). Returned only when the session is created. The session token sits in the fragment (`#token=…`), which browsers never send to servers; Druckling keeps only a hash of it. Hand the URL to the signed-in user's browser only, never log or cache it."
    },
    "template": {
      "type": "string",
      "description": "Slug of the template the session edits."
    },
    "permissions": {
      "type": "object",
      "properties": {
        "publish": {
          "type": "boolean",
          "description": "The user can publish new versions."
        },
        "assistant": {
          "type": "boolean",
          "description": "The AI assistant is offered. False when the plan doesn't include it, even if you asked for it."
        }
      },
      "required": [
        "publish",
        "assistant"
      ],
      "description": "What the editor offers beyond editing the draft."
    },
    "user": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "id",
            "name"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Your user, as you described them."
    },
    "theme": {
      "type": "object",
      "properties": {
        "mode": {
          "enum": [
            "light",
            "dark",
            "system"
          ],
          "type": "string"
        },
        "accent": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "mode",
        "accent"
      ]
    },
    "status": {
      "enum": [
        "active",
        "expired",
        "revoked"
      ],
      "type": "string"
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    },
    "revoked_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "test_mode": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "object",
    "url",
    "template",
    "permissions",
    "user",
    "theme",
    "status",
    "expires_at",
    "revoked_at",
    "test_mode",
    "created_at"
  ]
}
```