# Create a session

> Open the editor for one of your users. Returns a single-use client secret for your page.

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

## Body

<ParamTable params={[
  { name: "user.id", type: "string", required: true, description: "Your own id for this user (a number is sent as its string). The Muzekit user is created on the first session and reused after." },
  { name: "user.name", type: "string", description: "Shown in the editor." },
  { name: "user.email", type: "string", description: "For your records; Muzekit never emails end users." },
  { name: "user.locale", type: "string", description: "Editor language, e.g. en, de." },
  { name: "user.metadata", type: "object", description: "Your own data, up to 4 KB as JSON; more answers 400 invalid_request." },
  { name: "mode", type: "design | fill | view", description: "What the user can do. Default design. view needs a template. See Editor modes." },
  { name: "template", type: "tpl_… | key", description: "A template to open: its id or its key (external_id). One of your workspace templates or one of this user's own designs. An unknown one answers 404 template_not_found." },
  { name: "locale", type: "string", description: "Overrides the user locale for this session: en, de, es, fr, pt, ru or el (de-DE works too). Another language answers 400 invalid_request." },
  { name: "features", type: "object", description: "This session's editor, over the dashboard's Features page: { \"stock\": false, \"developer\": true }. Keys as in Features (insert, insertText, insertImage, insertVideo, insertShapes, canvasResize, uploads, links, stock, downloads, share, developer, removeBackground, aiImages, agent…)." },
  { name: "formats", type: "string[]", description: "Download formats for this session: png, jpg, webp, avif, pdf, html. Never metered." },
  { name: "videoFormats", type: "string[]", description: "Video download formats for this session, when video downloads are on: mp4, webm, gif, mov. Each uses API credits, 1 a second." },
  { name: "inspector", type: "string[]", description: "Design tab sections to hide for this session: align, position, appearance, typography, fill, media, video, waveform, border, shadow, effects, stacking, repeat, animate." },
  { name: "fonts", type: "all | brand", description: "brand: only the brand kit's fonts and the design's own." },
  { name: "maxPages", type: "number", description: "The most pages a design can have in this session (1–500)." },
  { name: "labels", type: "object", description: "Your own words for this session, up to 20: { \"muzekit.templates\": \"Designs\" }." },
  { name: "buttons", type: "object[]", description: "Up to 3 top-bar buttons: { id, label, action: event | png | pdf, primary? }. Clicks reach your page as the SDK's action event." },
  { name: "templatePicker", type: "string | object", description: "The templates picker for this session: \"panel\" or \"page\", or { layout: panel | page, open: blank | always | never, tab: auto | mine | templates }. See Editor modes." }
]} />

## Request

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "user": { "id": "user_42", "name": "Ada" }, "mode": "design" }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ user: { id: "user_42", name: "Ada" }, mode: "design" }),
});
const session = await res.json();
```

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

# json= sends the body with Content-Type: application/json
session = requests.post(
    "https://api.muzekit.com/v1/sessions",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={"user": {"id": "user_42", "name": "Ada"}, "mode": "design"},
).json()
```

</CodeTabs>

## Examples

### Open a template in fill mode

Your user fills in the fields of a template your team made, and the layout stays locked. Pass the template's key or its `tpl_…` id. The first change saves the user's own copy, so your template never changes; the SDK's `save` event then carries the copy's id with `created: true`.

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "user": { "id": "user_42", "name": "Ada" },
    "mode": "fill",
    "template": "product-card"
  }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    user: { id: "user_42", name: "Ada" },
    mode: "fill",
    template: "product-card",
  }),
});
// Send only the client_secret to your page
const { client_secret } = await res.json();
```

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

session = requests.post(
    "https://api.muzekit.com/v1/sessions",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={
        "user": {"id": "user_42", "name": "Ada"},
        "mode": "fill",
        "template": "product-card",
    },
).json()
client_secret = session["client_secret"]
```

</CodeTabs>

The response's `template` is what you sent, so a key stays a key:

```json
{ "object": "session", "mode": "fill", "template": "product-card" }
```

### Reopen a design your user saved

Store the `tpl_…` id from the `save` event (or the `template.created` [webhook](/docs/webhooks)) against your user. Open it in `design` mode later and saves update that design in place.

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "user": { "id": "user_42" },
    "mode": "design",
    "template": "tpl_Vk1t4l9xvQv"
  }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    user: { id: "user_42" },
    mode: "design",
    template: savedTemplateId, // "tpl_Vk1t4l9xvQv"
  }),
});
const session = await res.json();
```

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

session = requests.post(
    "https://api.muzekit.com/v1/sessions",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={
        "user": {"id": "user_42"},
        "mode": "design",
        "template": saved_template_id,  # "tpl_Vk1t4l9xvQv"
    },
).json()
```

</CodeTabs>

A design that belongs to another of your users won't open for this one.

### Give each pricing tier its own editor

Pick the switches from your own plan for the user. Session choices override the dashboard's Features page for this session only. Switches that cost or store something (uploads, stock, share links, video downloads and AI) are checked on Muzekit's servers too, so a user can't get around them from the browser.

<CodeTabs>

```bash tab="cURL"
# A basic-tier user: no stock or AI, PNG and JPG only, one page
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "user": { "id": "user_42" },
    "features": { "stock": false, "aiImages": false, "share": false },
    "formats": ["png", "jpg"],
    "maxPages": 1
  }'
```

```javascript tab="Node"
const TIERS = {
  basic: {
    features: { stock: false, aiImages: false, share: false },
    formats: ["png", "jpg"],
    maxPages: 1,
  },
  pro: {
    features: { aiImages: true, removeBackground: true, videoDownload: true },
    videoFormats: ["mp4", "gif"],
  },
};

const res = await fetch("https://api.muzekit.com/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ user: { id: user.id }, ...TIERS[user.tier] }),
});
const session = await res.json();
```

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

TIERS = {
    "basic": {
        "features": {"stock": False, "aiImages": False, "share": False},
        "formats": ["png", "jpg"],
        "maxPages": 1,
    },
    "pro": {
        "features": {"aiImages": True, "removeBackground": True, "videoDownload": True},
        "videoFormats": ["mp4", "gif"],
    },
}

session = requests.post(
    "https://api.muzekit.com/v1/sessions",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={"user": {"id": user.id}, **TIERS[user.tier]},
).json()
```

</CodeTabs>

AI features and video downloads spend your plan's AI and API credits, so turn them on only for users who pay you for them.

### Show a design for review

Open a `view` session for previews and approvals: nothing in the design can change. Turn `downloads` off too when the reviewer should only look.

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "user": { "id": "reviewer_7", "name": "Grace" },
    "mode": "view",
    "template": "tpl_Vk1t4l9xvQv",
    "features": { "downloads": false }
  }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    user: { id: "reviewer_7", name: "Grace" },
    mode: "view",
    template: "tpl_Vk1t4l9xvQv",
    features: { downloads: false },
  }),
});
const session = await res.json();
```

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

session = requests.post(
    "https://api.muzekit.com/v1/sessions",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={
        "user": {"id": "reviewer_7", "name": "Grace"},
        "mode": "view",
        "template": "tpl_Vk1t4l9xvQv",
        "features": {"downloads": False},
    },
).json()
```

</CodeTabs>

A view session opens your workspace templates and the session user's own designs. To show one user's design to someone else, open the session as its owner (`user.id` of the user who made it).

### Add a button that sends the design to your app

A top-bar button of your own, in your words. With `action: "png"`, a click sends your page the current page as a PNG in the SDK's `action` event (`base64`, `mimeType`). `labels` renames the editor's own buttons for this session.

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "user": { "id": "user_42" },
    "template": "product-card",
    "buttons": [
      {
        "id": "add-to-listing",
        "label": "Add to listing",
        "action": "png",
        "primary": true
      }
    ],
    "labels": { "downloads.download": "Export" }
  }'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    user: { id: "user_42" },
    template: "product-card",
    buttons: [
      { id: "add-to-listing", label: "Add to listing", action: "png", primary: true },
    ],
    labels: { "downloads.download": "Export" },
  }),
});
const session = await res.json();
// On your page: editor.on("action", (e) => upload(e.base64))
```

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

session = requests.post(
    "https://api.muzekit.com/v1/sessions",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    json={
        "user": {"id": "user_42"},
        "template": "product-card",
        "buttons": [
            {"id": "add-to-listing", "label": "Add to listing", "action": "png", "primary": True},
        ],
        "labels": {"downloads.download": "Export"},
    },
).json()
```

</CodeTabs>

## Response

```json
{
  "object": "session",
  "id": "ses_…",
  "client_secret": "ses_…_secret_…",
  "editor_url": "https://editor.muzekit.com/session",
  "expires_at": "2026-10-16T21:45:00.000Z",
  "mode": "design",
  "user": {
    "object": "user",
    "id": "usr_8fK2mQ1xZpR",
    "external_id": "user_42",
    "name": "Ada",
    "email": null,
    "locale": null,
    "metadata": {},
    "last_active_at": "2026-10-16T21:35:00.000Z",
    "created_at": "2026-10-02T09:12:44.000Z"
  },
  "template": null,
  "design": null
}
```

`user` is the [user](/docs/api-reference/users-list) as stored after this session's update.

In `fill` mode with one of your workspace templates, a user who already filled it gets their own copy back, so their earlier answers stay. `design` is that copy's `tpl_…` id, or `null` when the session starts from your template.

The `client_secret` works once and expires after 10 minutes. Pass it to the editor on your page; never store it.

The session counts toward your plan when the editor opens on your page, not when you create it. Creating one answers `402 sessions_exhausted` up front when this period's sessions and the 3% margin are used, so your server sees it before your user does.
