onAiChooseCommands is the AI’s model. With it, the AI’s ✦ stands beside Annotate’s button, and its selector offers Edit, where the person writes what they want, and Annotate, where the AI composes the annotations as an art director, the mode the ✦ opens on inside Annotate. The AI does what it is asked with the editor’s own tools, so everything it makes stays editable, and one Undo takes a whole request back. Edit is never offered Annotate’s tools: the Annotate mode is the one way to annotate with the AI. The AI commands do the same from code.
Full and Trial only. The Free and the Lite accept
onAiChooseCommands and ignore it: no AI shows, and their AI commands reject with NOT_AVAILABLE.How a Request Runs
- The editor calls
onAiChooseCommandswith the conversation and the tools. - The model answers with words, with calls to the tools, or with both.
- The editor runs each call as one of its commands, in order: the change lands on the photo, and the call’s result joins the conversation.
- Back to 1, until the model answers in words alone. That answer is the reply the person reads.
onAiChooseCommands. While it works, the person sees each change land, the AI’s card at the top of the photo says what the AI is doing, a light sweeping across its words, and the photo’s edge glows in the colors of the AI’s brush. When a round runs 15 seconds late, a second line under it says it is taking a little longer than usual; while a tool the model called runs one of your pixel functions (a fill, a cut, a find), the line waits 50 seconds, as those take longer, and once your function answers, the next round gets its 15 seconds again, counted from then.
Wire It
In the page,onAiChooseCommands posts the conversation to your server:
page.tsx
Request (Cloudflare Workers, Deno, Bun, Hono) takes the same function. On Cloudflare Workers, write it as On Cloudflare Workers shows, so the person’s Stop reaches the model’s call.
route.ts
mountEditor and openEditor, pass the same function as their onAiChooseCommands option.
The body grows with the request, every screenshot in it. Computed at the editor’s JPEG from the prototype’s runs, the request with the most screenshot bytes (ten screenshots of a busy street) sends about 2.7 MB on its last round, and a longer request sends more. A platform that caps request bodies needs room for it: Vercel Functions take at most 4.5 MB.
What the Editor Sends
The conversation so far, in OpenAI’s Chat Completions shape, the one most services take. Your function gets a copy: what it does to the array never reaches the conversation.
The tools the model may call, in the same shape: the editor’s commands. See The tools.
Aborts when the request stops: the Stop on the AI’s card, Escape,
ask.stop() or ask.end(), the editor closing or leaving the page, or another image opening. Pass it to your fetch, and your server to the model’s call, so a stopped request stops costing.- The guide, as a system message: the editor’s rules for using its tools, looking at the photo, writing text and composing annotations. It includes the editor’s language and changes when the available Annotate tools, language or your
aiPromptschange. Its parts can be replaced: see Customize the Prompts. - The person’s request, as a user message. The editor adds context for a marked area, the whole photo or a new background, including its box and the tools to use. Annotate requests also get a line identifying the mode; Generate again asks for another composition. The actual lines can be replaced with
aiPrompts: see Customize the Prompts. - Each round: the message your function returned, as it returned it; a
toolmessage for each tool call, its content the command’s result as JSON; and, after a turn’s tool messages, one user message with that turn’s screenshots. - The next request in the same conversation, as a user message after all of that, the system message as it stands then: the same unless Annotate was turned on or off, the editor’s language or your
aiPromptschanged meanwhile.
tool message’s content, and again the text right before its image. For a 3000 × 2000 photo, the first round’s answer and what follows it:
messages.json
The Tools
Each tool is one of the editor’s commands, ascommands() gives it, under its name in snake_case, as OpenAI’s format takes no dot: annotate_add, read_screenshot, and annotate_add_arrow for annotate.addArrow. Its description says what it does and when it rejects, with an example call (read_screenshot’s says how its picture comes: a JPEG at most 1024 px on its longer side, with its note; read_state’s that the AI’s own edits are pixels the state never holds, an Expand’s bigger photo aside, which read_screenshot shows), and its parameters are its input’s JSON Schema, but retouch_run’s area, which takes { "kind": "MARK" }, { "kind": "ALL" } and { "kind": "BACKGROUND" } alone: a box the model picked went to the fill, which redrew what stood in it, where the whole photo’s edit keeps the rest. A POLYGON or a RECT the model sends is answered INVALID_COMMAND, input.area.kind, your onAiEditImage never asked; your own retouch.run() takes them, and the model’s retouch_remove keeps them, to remove a thing by its box. Annotate’s tools carry the manual of every piece there: each field’s description says what it does on the photo, when to use it, and what it takes where a call leaves it out: a new piece, its tool’s last style; an arrow added to a text, an added arrow’s default; annotate_update, the value it has. Each Annotate tool that places or moves an annotation answers with boxes, where each one landed once laid out, in image px (Where It Landed), so the model checks overlaps and margins without working out a text’s width; Obfuscate’s and the marks’ tools that place or move an area or a mark answer the same way (Where It Landed), so it checks what an area covers.
- In: every command that edits or reads the photo:
obfuscate,crop,size,filter,frame,adjust,auto,marksand the reads,read_markamong them, the boxes of the areas the person marked with the AI’s brush; the history (history_undo,history_redo,history_reset) and the output (output_save,output_export_file); andeditor_closewhere you giveonClose, or the editor isopenEditor()’s modal.retouch_run,retouch_removeandcrop_expandare there only when you giveonAiEditImage,retouch_remove_backgroundonly when you giveonAiRemoveBackground, andobfuscate_detectonly when you giveonAiDetectObjects, in a request ofask.send(): a request of the Annotate mode (annotate.create(),annotate.recreate()) never changes pixels. A request ofask.send()is offered none of Annotate’s commands (annotate_*) norread_options, and a request of the Annotate mode is offered them. An agent over MCP is offered the same list with Annotate’s commands. - Out: the editor’s menu and view (
menu,view), the conversation itself (ask), Annotate’sopen,close,createandrecreate, and the person’s own controls, which change what the person works with next and never the photo:annotate.select,annotate.setStyle,annotate.setTheme,annotate.setTool,obfuscate.select,obfuscate.setLook,palette.set, the mark and its brush (retouch.mark,retouch.moveMark,retouch.removeMark,retouch.erase,retouch.unmark,retouch.selectMark,retouch.setBrush), the Aspect section’scrop.setMode, and a Generate or an Expand asked again (retouch.more,crop.more): the model reads the mark, never makes it. - Out too, a tool you turned off: its commands would only answer
NOT_AVAILABLE, so they never reach the model. WithenableAnnotate: falseit gets noannotate_*tool and noread_options; the same goes forenableFilter,enableFinetune(adjustandauto),enableFrame,enableObfuscateandenableResize(size), and formarkswhile there is no mark the person can adjust (none, or only fixed ones).
history_undo takes back the request’s own last call, whole, and with none made yet the step before the request, as the toolbar’s Undo; history_redo brings them back. The request still ends as one undo step. output_save saves as the Save button does, onProcess and the save event included; where Save closes the editor (the modal), and on editor_close, the request ends there, the host’s onAiChooseCommands asked no more: ask.send() rejects NOT_AVAILABLE once the editor is gone, as on the person’s Close, and resolves with its words so far where the editor stays. Nothing the AI makes is selected, and an Undo or Redo of its step selects nothing it made.
The list is the same on every round of a request, so it caches with the guide. A call that fails is answered as that tool’s content, its code and the paths it names, with the schema’s issues where the input was off it, {"code":"INVALID_COMMAND","issues":[…],"props":["input.piece.at"]}, and the model fixes it: the person never sees it. A linked agent reads the same texts.
What It Gives Back
The model’s next message, in the same shape:Its words, or
null. Words beside tool calls show on the AI’s card as what the AI is doing (the guide asks for one short phrase before each action); without them, the card shows a phrase of the editor’s for the tool, such as Looking at the photo…. Words alone end the request: they are its reply.The tools it calls, run in order: each with its
id, the tool’s name and its arguments as the JSON text the model wrote.AI_FAILED: the AI’s card says Couldn’t Complete the Request, with your error’s message under it, so write that message for the person, in their language. A rejection that is no Error, an Error with no message, or one of the editor’s own (EmbedEditorError) shows Try again. under the title. Either way the request’s command (ask.send(), annotate.create() or annotate.recreate()) rejects with AI_FAILED, its cause your rejection as it came. What the AI did so far stays, as one undo step, and the conversation keeps it. An answer that is no message, or whose tool_calls is no list of calls, ends it the same way, with Try again. under the title, and stays out of the conversation. An abort through signal is a stop, and shows no notice.
The Rules
- The conversation only grows. The editor appends, and never edits or removes a message. The current models reject a history edited around their saved reasoning, and a cache reads only a start identical to the one before. Send the messages to the provider in order, each one every round.
- Keep what you return whole. Every message you return comes back to you on the next round exactly as you returned it, extra fields included. Keep the provider’s own content there and send it back as it came.
- The screenshot follows the tool messages. Chat Completions takes no image in a
toolmessage, soread_screenshotanswers with its note, and the turn’s images follow in one user message after that turn’s tool messages, each one after its note. Where the provider takes images in a tool’s result, as Claude’s and OpenAI’s Responses APIs do, fold each image into the result its note answers. The servers below do. - Cache first. The guide and the tools repeat on every round, and they are most of what a round sends. Turn the provider’s cache on: in the prototype, 89% of the input tokens sent came from the cache, at a tenth of the input price or less on Claude.
- Add rules the same way every round. Your server may add its own rules to the system message (“use our brand’s colors”). Add them identically on every round, so the start stays cached.
- A weak model can loop. The editor stops a request at 30 rounds. A model that can’t close the loop of placing, checking and fixing reaches that limit, removing and placing its pieces again. See Which model.
- One conversation per photo. The next request goes on in the same conversation, so the model knows what it did (“make the 2 bigger”). Your
ask.end()ends it, and so does another image opening; the person closing the AI by its lit ✦ keeps it (ask.close()).
Which Model
Choose a model that can use tools and read images. Our recommended server uses Claude Sonnet 5.5. In the Annotate bench on 2026-11-21, a composition averaged 46 seconds and US$ 0.13 over two runs on 12 photos, with about eight rounds per composition. Two blind judges graded the results; these estimates depend on the request and the provider’s prices.- Claude Sonnet 5.5: the recommended balance of quality and cost.
- Claude Opus 5.5: a more expensive alternative that gave more imaginative compositions in our pilot, measured on four photos.
- Claude Haiku 5.5: a cheaper alternative, but its compositions were less consistent. Its cost was under a cent per composition in an earlier test with a different guide.
Prices
Each server below takes the model as a string, so moving from Sonnet to Haiku or Opus is one word. In US$ per million tokens, as each provider listed them in November 2026:
Claude’s and Gemini’s prices are from their own pricing pages, OpenAI’s from its help center’s rate table. Each round sends the whole conversation, so the cache read is the price that counts most: in our measurements about 90% of a composition’s input came from the cache.
Servers
Each server is one module for your server, with the samechooseCommands function: it takes the editor’s messages and tools, the model and the signal, sends the conversation in the provider’s own shape, and resolves to { message, usage }, the model’s answer in the editor’s shape and what the round used. Each one:
- sends the system message where the provider wants it;
- sends the tool results the provider’s way, each screenshot inside its result where the provider takes it;
- leaves out an assistant message with neither words nor tool calls;
- keeps the provider’s own content on the message it gives back, and sends it back as it came;
- has the provider’s cache on;
- rejects an answer the model stopped short of (a refusal, or the output limit with a tool call perhaps cut off), so the editor says Couldn’t Complete the Request instead of running half a call.
Claude
The Messages API, each screenshot folded into thetool_result it answers, with automatic caching. The editor’s own bench runs this file (yarn editor ai:bench), word for word. It needs @anthropic-ai/sdk and ANTHROPIC_API_KEY. cost() prices a round at Anthropic’s prices of November 2026, for your own metering.
claude.ts
OpenAI
The Responses API: in the prototype, OpenAI’s newer models refused an image beside tools through Chat Completions. Each screenshot goes into thefunction_call_output it answers. It needs the openai package and OPENAI_API_KEY.
store: false: OpenAI keeps no copy, and the conversation is the editor’s.include: ['reasoning.encrypted_content']has the reasoning come back encrypted, so OpenAI’s items, that reasoning among them, ride on the message and go back as they came.strict: falseon each tool: the editor’s schemas leave optional fields out ofrequired, which OpenAI’s strict mode refuses.- The cache is OpenAI’s own, on with no setting: the conversation only grows, so each round starts as the round before.
openai.ts
Gemini
Chat Completions, through Google’s OpenAI-compatible endpoint, with theopenai package and GEMINI_API_KEY. The editor’s messages go as they are, but for an empty assistant turn.
- The screenshot can’t go inside the tool’s answer. A
toolmessage takes text alone in Chat Completions, so each screenshot stays in the user message after the turn’s tool messages, where the editor puts it. - The thought signatures go back. Gemini 3 signs its tool calls and needs the signatures back on the next rounds; Google’s OpenAI compatibility carries them in Chat Completions. The server keeps each tool call whole, as Gemini gave it, and the editor sends it back as it came.
- The cache is implicit, on with no setting in Gemini 2.5 and later.
- Google calls its OpenAI compatibility a beta.
gemini.ts