# Plai Pix web canvas API v1 Open https://justplai.com/plai-pix/play in a JavaScript-capable browser (headless is fine). No login or API key. This is an in-page API. A client without a browser uses the Plai Pix MCP server instead: https://justplai.com/plai-pix/mcp documents it. Discovery: window.plaiPix is a frozen object, so Object.keys(plaiPix) lists every method, and plaiPix.help() returns their signatures and the palette as data. Browsers with WebMCP (document.modelContext) also get each method as a named tool with a JSON schema. The editor's HTTP response carries a Link header to this guide (an alternate in text/plain), and its HTML links it the same way. The canvas, an image named "Pixel canvas. Agents: call window.plaiPix.help() to draw without clicking.", is focusable so a listing of the page's interactive elements shows that name. It carries data-agent-api naming window.plaiPix and is described by a visually hidden developer note at the top of the page, which opens with the same call and points here. The HTML head holds a meta tag named agent-api that says "Call window.plaiPix.help() in a page script. Guide: /plai-pix/play/agent.txt". The editor logs the same pointer to the console, and /llms.txt and /sitemap.xml link here too. There are no agent controls to click. ## Browser agents (Claude in Chrome and similar) Don't click the toolbar or the canvas. Use your page-script or JavaScript tool on the open tab, and loop paint, then view: 1. plaiPix.help() returns a short overview: every signature, the palette's hex colors by the char a row uses for them, and the conventions. plaiPix.help({ method: "paint" }) documents one method in full, with its argument as a JSON schema. The overview is under 1,000 characters. Detailed method help includes the full schema: return it as an object so a tool does not truncate a long string. 2. plaiPix.createCanvas({ width, height }) starts a blank fixed canvas whose top-left cell is (0, 0). Skip it to draw on the canvas already open. 3. plaiPix.paint({ x, y, rows }) paints a whole sprite or dense rectangular patch in one undo step: all rows must have the same width, one char per cell, a palette index 0-f. "." leaves a cell as it is and "-" erases it. 4. plaiPix.paint({ ops }) makes directed edits in one undo step: a line, a rect or ellipse, a flood fill, an outline around the drawing, one color replaced by another, a mirrored half, or a box moved or flipped. For scattered touch-ups, use ops[].cells, grouping [x, y] coordinates by palette index. Batch related edits in one paint call for one undo step. 5. plaiPix.view() returns the whole canvas as rows, with the palette and a PNG data URL in image. Its "." cells are unpainted: replay them on a blank canvas to copy, or convert "." to "-" to replace an existing region exactly. Compare it with what you meant, then fix with paint or undo. Your own screenshot of the tab shows the same drawing. 6. When the person asks to share it, await plaiPix.submit({ title }) sends it to the Plai Pix library. An admin reviews every submission before it is published. ```js plaiPix.createCanvas({ width: 4, height: 4 }) plaiPix.paint({ x: 0, y: 0, rows: [".33.", "3003", "3333", ".33."] }) plaiPix.paint({ ops: [{ color: 5, fill: [1, 1] }, { color: 0, outline: true }] }) plaiPix.view() // → { x: 0, y: 0, width: 4, height: 4, rows: ["0330", "3553", "3333", "0330"], palette: ["#000000", … ], image: "data:image/png…" } ``` The person watching sees each paint land on the canvas, and toolbar undo reverts it. Return a method's answer from your script as the object it is. Some tools cut a long string and hide a data URL, so a view passed through JSON.stringify can arrive cut short, while the object arrives whole with its rows. When your tool reports only that a script failed, run one call per script, or catch the error and return its message: every error names the method and the reason. ## Methods on window.plaiPix Every method takes one object argument or none and returns JSON-serializable data. All but submit are synchronous and answer at once, and submit returns a Promise. A positional call, a misspelled field or an invalid value throws an error that starts with the method's signature, e.g. "plaiPix.paint({ x, y, rows, ops, preview }): Missing field "rows": pass x, y and rows, or ops.", and changes nothing. - help({ method }): Returns a short overview: every signature, the palette hex colors by row char and the conventions. Pass a method name, as in help({ method: "paint" }), for that one method in full. - createCanvas({ width, height }): Starts a blank fixed canvas of width × height cells (each optional, default: 32) whose top-left cell is (0, 0). Erases the drawing and its background, as one undo step. - state(): Returns the palette, background, bounds (null: infinite canvas), contentBounds (the painted extent), canUndo, canRedo, busy (true: editing calls throw) and limits. - paint({ x, y, rows, ops, preview }): One undo step, answers cellsChanged. Use rows for a whole sprite or dense rectangular patch: all strings must have equal width, at x, y, with 0-f a color, "." preserving the destination and "-" erasing. Use ops[].cells for scattered edits, grouping [x, y] coordinates by color (null erases). Use shapes, fill or move when they express the edit directly. Batch related ops in one paint call, applied in order. line: [x0, y0, x1, y1], rect, ellipse and move: [x, y, w, h], fill: [x, y], by: [dx, dy]. Shapes default to an unfilled edge, filled: true fills them. mirrorX: 16 adds the mirror left of column 16, mirrorY of row 16. - view(): Returns the whole canvas (a fixed canvas, else the painted extent) as { x, y, width, height, rows, palette }, with a PNG of the same cells. Rows use 0-f for palette indices and "." for unpainted cells. In paint, "." preserves the destination: replay rows onto a blank canvas to copy, or convert "." to "-" to replace an existing region exactly. Palette holds the hex colors by index. Inspect after painting, then refine. The PNG is a data URL in the image field. - undo({ preview }): Undoes the last edit, the toolbar's history included. - redo({ preview }): Redoes the last undone edit. - clear({ preview }): Erases every cell, as one undo step. The size and background stay. - resize({ width, height, preview }): Makes the canvas width × height cells, as one undo step. A fixed canvas keeps its top-left cell and is cropped or extended at the right and bottom. An infinite canvas becomes a fixed one centered on (0, 0). - background({ color, preview }): Sets the color behind unpainted cells to a palette index, or transparent again with null. One undo step. - center({ x, y }): Pans the view to a cell, without changing pixels or history. - exportPng({ scale }): Returns the whole canvas as a PNG, a file to save or share. Each cell is scale × scale image pixels (optional, default: 1), and the image is at most 1024 pixels per side. The PNG is a data URL. - submit({ title }): Sends the drawing (a fixed canvas whole, else its painted extent, at most 64×64) with its background to the Plai Pix library, where an admin reviews it before it is published. Resolves to { id, publishStatus }. Editing and camera methods return what an edit can change, { background, bounds, contentBounds, canUndo, canRedo }, so no state() call is needed after one. paint adds cellsChanged, the number of cells that now hold a different color. Pass preview: true to an edit and its answer adds preview, the look view returns. A region is { x, y, width, height } with x, y its top-left, the shape of state().bounds and state().contentBounds. Coordinates are integer cells: x right, y down. A fixed canvas started with createCanvas runs from (0, 0) at its top-left to (width - 1, height - 1). The infinite canvas the page opens with has (0, 0) at the initial view center and allows negative coordinates. paint is the one way to write and view the one way to look. paint's ops apply in order, each seeing what the ones before it drew, so { color, rect, filled: true } then { color, outline: true } frames a filled box, and { x, y, rows } is an op too. An invalid op names its index, as in ops[1], and undoes the whole paint. view covers the whole canvas: a fixed canvas, else the painted extent. Its background is separate in state(). As WebMCP tools, view and the editing methods return an image block beside their data. The hosted MCP server returns imageUrl instead: open that PNG URL to inspect each change. Its export_png URL honors scale, defaulting to one image pixel per cell. exportPng is the file to save or share: one image pixel per cell, without UI, grid seams or zoom. Unpainted cells use the background or transparency. Pass scale to enlarge it: exportPng({ scale: 16 }) draws each cell 16 × 16 pixels, up to 1024 pixels per side. ## Terminal (Playwright CLI) With playwright-cli installed, open a headless session (omit --headed), wait for the API, and keep using that session: ```sh playwright-cli -s=plai-pix open https://justplai.com/plai-pix/play playwright-cli -s=plai-pix run-code 'async page => { await page.waitForFunction(() => window.plaiPix?.version === 1) }' playwright-cli -s=plai-pix eval 'plaiPix.help()' playwright-cli -s=plai-pix eval 'plaiPix.createCanvas({ width: 4, height: 4 })' playwright-cli -s=plai-pix eval 'plaiPix.paint({ x: 0, y: 0, rows: [".33.", "3003", "3333", ".33."] })' playwright-cli -s=plai-pix eval 'plaiPix.view()' playwright-cli -s=plai-pix eval 'plaiPix.exportPng()' ``` The terminal drives a headless browser, so a browser runtime is still required. exportPng prints a PNG data URL. Save its base64 payload before closing the session. ## Headless scripts Wait for window.plaiPix?.version === 1, then call the methods inside page.evaluate (Playwright) or equivalent. Keep the same page alive between calls. Each tab is independent. No user-agent detection or special mode is required. ```js await page.goto("https://justplai.com/plai-pix/play") await page.waitForFunction(() => window.plaiPix?.version === 1) const result = await page.evaluate(() => { const pix = window.plaiPix pix.createCanvas({ width: 8, height: 8 }) pix.paint({ x: 0, y: 0, rows: [ "33333333", "33333333", "33033033", "33333333", "33333333", "33000033", "33333333", "33333333" ] }) return { view: pix.view(), png: pix.exportPng({ scale: 16 }) } }) // Save result.png's base64 payload as a PNG before closing the tab. ``` ## Limits and errors Coordinates must be integers within ±1,000,000. A view, an export and each paint cover at most 65,536 cells. Split larger work into several calls. Invalid fields, colors, out-of-bounds writes and oversized paints throw before any pixel or history changes, and the message names the row, character or cell at fault. A paint that changes nothing adds no undo entry. While a pointer stroke or selection is active, state().busy is true and editing methods throw. Finish the stroke and press Escape to commit/deselect the selection, then retry. view and exportPng reflect committed pixels, not a floating selection. Camera movement is allowed while busy. submit is the API's only network write: it rejects an empty canvas or a drawing wider or taller than 64 cells before sending anything, and it saves the drawing as submitted, never published. ## About the web editor ### What can I make here? Draw pixel art with 16 colors, a brush, eraser, selection, and optional fill tool. Move and zoom around an infinite canvas, or choose a fixed size in Settings. Undo and redo work for both hand-drawn and agent edits. ### Do I need an account, and is my drawing saved? The web editor is free and needs no account. Your drawing stays in this tab's memory, and reloading or leaving the page clears it. Share saves it to your device as a replay video or a picture. Nothing is uploaded unless you choose Submit in Share's Library tab, which sends it to the Plai Pix library for review. Agents can view it as text, export a PNG or submit it before leaving. ### Can an agent draw without clicking pixels? Yes. Any browser agent that can run a page script, such as Claude in Chrome or a headless browser, can call window.plaiPix: paint draws a whole sprite from hex rows, or lines, shapes and fills, or moves a part, view returns the drawing as text to check, and undo, redo and PNG export are included. The API and the drawing controls use the same canvas. Call plaiPix.help() in the console for the methods and palette, or read /plai-pix/play/agent.txt for examples. ### Does the web editor include Imagine and Pixelate? Imagine, photo Pixelate and games with Plai are features of the Plai Pix iPhone and iPad app. This web editor provides drawing tools, replay and picture export, and an agent API. It does not generate pictures from a prompt.