Developers

One API for files, commands and agents

Everything the editor does, your programs can do. Files are JSON documents; changes are commands on the same channel the UI uses. Base URL: https://design.sweetai.work. All responses are JSON; errors look like {"error": "File not found."} — a human message, never a raw code.

Authentication

Two ways in

Session cookie — for browsers

Log in at /login and the browser carries an HttpOnly session cookie. The editor and the home page use it; so can any same-site page you build.

API token — for programs

Create a personal API token in Home → API: give it a name, copy it when it is shown — it is displayed exactly once and only its hash is stored. Send it on every request:

Revoke a token at any time from the same panel; revocation takes effect immediately. A token acts with your account's full file access, so keep it like a password.

# Every /api/* endpoint accepts the token: curl https://design.sweetai.work/api/files \ -H "Authorization: Bearer sd_…" # Who am I? curl https://design.sweetai.work/api/auth/me \ -H "Authorization: Bearer sd_…" # → {"id": "…", "email": "[email protected]", # "name": "…", "role": "user"}
MethodPathWhat it does
POST/api/auth/registerCreate an account {email, password, name?} and start a session.
POST/api/auth/loginStart a session {email, password}.
POST/api/auth/logoutEnd the current session.
GET/api/auth/meThe signed-in user (cookie or Bearer token), or 401.
GET/api/tokensYour API tokens — metadata only, never the secrets.
POST/api/tokensCreate a token {name}. The response carries the full token once.
DELETE/api/tokens/:idRevoke a token.

Files API

Your design files, as JSON

Files belong to the signed-in user; another user's file is indistinguishable from a missing one (404). A document is { name, pages: [{ id, name, root }], components, styles, variables } — every node is { id, type, name, x, y, w, h, fills, strokes, children, … }.

MethodPathWhat it does
GET/api/filesList your files, newest first — metadata only (id, name, created_at, updated_at).
POST/api/filesCreate a file {name?}, seeded with the starter document.
GET/api/files/:idThe file, including the full document as doc.
PUT/api/files/:idReplace the name and/or the whole document {name?, doc?} — this is what the editor's autosave sends.
DELETE/api/files/:idDelete the file.
POST/api/files/:id/commandsApply commands to the stored document — see below.

Commands

Edit without opening the editor

POST /api/files/:id/commands runs your commands through the same DocStore engine the UI uses. Commands apply in order against the evolving document; if any command is invalid — unknown type, missing page, dangling node id — the whole batch is rejected with a 400 and the stored document is left untouched.

# Add a banner to a frame, then rename it: curl -X POST \ https://design.sweetai.work/api/files/FILE_ID/commands \ -H "Authorization: Bearer sd_…" \ -H "Content-Type: application/json" \ -d '{ "commands": [ { "type": "addNode", "pageId": "PAGE_ID", "parentId": "FRAME_ID", "node": { "id": "hero-banner", "type": "rectangle", "name": "Hero Banner", "x": 0, "y": 0, "w": 320, "h": 180, "fills": [{"color": "#5b5bd6", "opacity": 1}], "strokes": [], "cornerRadius": 12, "children": [] } }, { "type": "setProps", "patches": [ {"id": "hero-banner", "props": {"name": "Hero"}} ] } ] }' # → {"ok": true, "name": "Untitled", # "updated_at": "…", "nodeCount": 128}

Get real PAGE_ID / FRAME_ID values from GET /api/files/:id — page ids are doc.pages[i].id, node ids live in each page's root tree. Node ids you add must be unique in their page.

CommandFields
addNodepageId, parentId, node, index?
removeNodespageId, ids[]
setPropspatches: [{id, props}] — props are merged onto the node
reorderpageId, id, toIndex — within the current parent
reparentpageId, items: [{id, parentId, index?, props?}]
createComponentpageId, id
renamePage / renameDocpageId, name / name
addPage / removePagepage / pageId
compositecommands[] — a batch, applied in order
setDocdoc — replace the whole document

Node types: frame, section, rectangle, ellipse, line, polygon, star, text, image, group, component, instance, vector, slice. Text nodes carry text, fontSize, fontWeight, textAlign.

In the editor

window.sd

Open the editor, open your browser console: the same channel is exposed as window.sd for the open document. Calls are synchronous; reads return deep copies.

CallWhat it does
sd.getDocument()A deep snapshot of the whole document JSON.
sd.execute(command)Run one command (same vocabulary as above) — lands in the undo history.
sd.executeAll(commands)Run several commands as one composite = one undo step.
sd.getSelection()The selected nodes on the active page, as full node objects.
sd.findNodes(query)Find nodes across all pages by name substring or exact type (or {name, type}); results are tagged with their pageId.
sd.undo() / sd.redo()Walk the same undo stacks as ⌘Z.

MCP

The MCP server

A small local MCP server (Node, official SDK, stdio transport) bridges any MCP client to the REST API with your token. No browser tab needs to be open — the agent works on the stored files directly.

Setup

1. Create a token in Home → API.
2. Clone the SweetDesign repo and run npm install in its mcp/ directory (Node ≥ 18).
3. Point your MCP client at it:

Full instructions live in mcp/README.md in the repo. SD_API_BASE defaults to https://design.sweetai.work and only needs setting for a local dev instance.

// claude_desktop_config.json (same shape for // any stdio MCP client): { "mcpServers": { "sweetdesign": { "command": "node", "args": ["/path/to/sweetdesign/mcp/index.js"], "env": { "SD_API_TOKEN": "sd_…", "SD_API_BASE": "https://design.sweetai.work" } } } }
ToolArgumentsWhat it does
list_files—Your files: id, name, created_at, updated_at.
get_filefileIdFile metadata plus the full document JSON.
create_filename?Create a file seeded with the starter document.
execute_commandsfileId, commands[]Apply commands (vocabulary above) to the stored document, server-side.
rename_filefileId, nameRename a file.
delete_filefileIdDelete a file.