Skip to Content

Inpaint and outpaint

Redraw part of an image with a mask, or extend it past its edges.

qwen-image/inpaint changes one part of an image and keeps the rest as it was. Send the image, an instruction in prompt, and one of:

  • mask: an image the same size as yours, white where the model redraws and black where your image stays as it is. Use it to remove or replace something: "Remove the man", "Add a lamp on the sideboard".
  • outpaint: pixels to add on any side, {"left": 600} or {"top": 200, "bottom": 200}. The model draws the new area to match: "Extend the beach to the left".

Away from the mask, or inside the old edges, the result keeps your image's own pixels. Poll the result like any generation.

# Remove the man: the photo and its mask, both inline as data URLs
curl https://tensorfactory.ai/v1/generations \
  -H "Authorization: Bearer $TENSORFACTORY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"model": "qwen-image/inpaint", "prompt": "Remove the man",
       "image": "data:image/jpeg;base64,'"$(base64 < street.jpg | tr -d '\n')"'",
       "mask": "data:image/png;base64,'"$(base64 < street-mask.png | tr -d '\n')"'"}'

# Extend a photo 600 pixels to the left
curl https://tensorfactory.ai/v1/generations \
  -H "Authorization: Bearer $TENSORFACTORY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"model": "qwen-image/inpaint", "prompt": "Extend the beach to the left", "image": "https://example.com/beach.jpg", "outpaint": {"left": 600}}'

Make a mask

  • The same width and height as the image, in pixels. Another size answers 400 naming mask.
  • White (any grey of 128 or more) is redrawn, black is kept. Transparent pixels count as white, so a PNG with the area to redraw cut out works too.
  • Paint a little past the edges of what you remove, its shadow included: the model only redraws what the mask covers.
  • mask takes the same forms as image: an https link, a data URL or an upload's asset_id. The image and the mask together are at most 7 MiB.

Outpaint limits

Outpaint is in beta: on some seeds the new margins can cut a subject at the old edge or show a visible line where the photo meets the new area. Run it again with another seed if that happens. A mask fill is not affected.

  • Send any of left, top, right and bottom, whole numbers of pixels. The rest are 0, and at least one is more than 0.
  • The result is at most twice your image on each side: a 1000 x 800 image takes up to 1000 pixels more across (left and right together) and 800 more down.
  • The image, and the result with its margins, are each at most 8192 pixels a side and 16,777,216 pixels.

The generation shows what you sent: mask (its upload's asset_id) or outpaint (the four margins), the other null. result.width and result.height are the image's size, plus the margins.

What else it takes

  • Send mask or outpaint, not both, and one of them: either mistake answers 400.
  • No aspect_ratio, resolution, image_2, image_3 or transparent_background: the result is your image's size.
  • seed and output_format as for an edit. A prompt that names a real person is refused, as for any edit.
  • It takes no steps or mode: a fill with a mask runs 8 steps, an outpaint 4. The generation's steps shows which. Prices are on Pricing.

On this page