Skip to content

Brush edits and masks

mode: "brush" changes only the area you mark. Everything outside it stays exactly as it was. Describe the change in prompt, or pass preset: "remove" to take away what is marked.

There are two ways to mark the area: brush strokes in JSON, or a mask image you upload.

Upload a PNG the same shape as the photo (any size: it is scaled to fit) and pass its id as maskAssetId.

  • On a mask with transparency, transparent pixels mark the area to change. This is the same convention as OpenAI’s images.edit, so masks you already make for it work here.
  • On a mask without transparency, white pixels mark the area to change and black pixels are kept.
const photo = await client.uploads.create('./kitchen.jpg');
const mask = await client.uploads.create('./kitchen-island-mask.png');
const design = await client.designs.createAndWait({
mode: 'brush',
inputAssetId: photo.id,
maskAssetId: mask.id,
prompt: 'A white marble island with brass stools',
});

If your product has its own brush tool, send the strokes as they were drawn. Points are [x, y] pairs from 0 to 1 across the photo, so they do not depend on the photo’s pixel size. size is the brush diameter as a fraction of the photo’s shorter side (0.01 to 0.3). An erase stroke takes paint away again.

{
"mode": "brush",
"inputAssetId": "01a1ebfd-494e-752c-86b5-d58f61313030",
"preset": "remove",
"mask": {
"strokes": [
{ "points": [[0.42, 0.61], [0.47, 0.63], [0.55, 0.64]], "size": 0.08, "mode": "paint" }
]
}
}
  • Cover the whole object plus a small margin. A tight outline leaves a halo of the old object.
  • The marked area must be between about 0.5% and 90% of the photo, or the API answers 422 invalid_mask.
  • To place a product of your own, upload its photo and pass it in itemAssetIds with a prompt such as “Put this armchair in the marked corner”.