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.
| Method | Path | What it does |
|---|---|---|
| POST | /api/auth/register | Create an account {email, password, name?} and start a session. |
| POST | /api/auth/login | Start a session {email, password}. |
| POST | /api/auth/logout | End the current session. |
| GET | /api/auth/me | The signed-in user (cookie or Bearer token), or 401. |
| GET | /api/tokens | Your API tokens — metadata only, never the secrets. |
| POST | /api/tokens | Create a token {name}. The response carries the full token once. |
| DELETE | /api/tokens/:id | Revoke 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, … }.
| Method | Path | What it does |
|---|---|---|
| GET | /api/files | List your files, newest first — metadata only (id, name, created_at, updated_at). |
| POST | /api/files | Create a file {name?}, seeded with the starter document. |
| GET | /api/files/:id | The file, including the full document as doc. |
| PUT | /api/files/:id | Replace the name and/or the whole document {name?, doc?} — this is what the editor's autosave sends. |
| DELETE | /api/files/:id | Delete the file. |
| POST | /api/files/:id/commands | Apply 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.
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.
| Command | Fields |
|---|---|
| addNode | pageId, parentId, node, index? |
| removeNodes | pageId, ids[] |
| setProps | patches: [{id, props}] — props are merged onto the node |
| reorder | pageId, id, toIndex — within the current parent |
| reparent | pageId, items: [{id, parentId, index?, props?}] |
| createComponent | pageId, id |
| renamePage / renameDoc | pageId, name / name |
| addPage / removePage | page / pageId |
| composite | commands[] — a batch, applied in order |
| setDoc | doc — 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.
| Call | What 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.
| Tool | Arguments | What it does |
|---|---|---|
| list_files | — | Your files: id, name, created_at, updated_at. |
| get_file | fileId | File metadata plus the full document JSON. |
| create_file | name? | Create a file seeded with the starter document. |
| execute_commands | fileId, commands[] | Apply commands (vocabulary above) to the stored document, server-side. |
| rename_file | fileId, name | Rename a file. |
| delete_file | fileId | Delete a file. |