Skip to Content

Edit a photo

Send a photo by link or inline, and change it with one sentence.

Send the photo in the same call that starts the edit. image takes an https link to a JPEG, PNG or WebP file, or the image itself as a data URL (data:image/jpeg;base64,...). The image_url of an earlier generation works too, while TensorFactory still has that image: before its first download, and at most 10 minutes after its run. Poll the result like any generation.

# Start the edit with the photo inline as a data URL, then poll it like any generation
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/edit", "prompt": "Replace the background with a warm minimalist studio with a soft beige backdrop. Keep the mug'"'"'s shape, color and printed logo unchanged.", "image": "data:image/jpeg;base64,'"$(base64 < photo.jpg | tr -d '\n')"'"}'

curl "https://tensorfactory.ai/v1/generations/$ID?wait=10" \
  -H "Authorization: Bearer $TENSORFACTORY_API_KEY"

For a photo already online, send its link instead: "image": "https://example.com/mug.jpg".

If you retry, send the same body with the same Idempotency-Key: you get the first run back, not a second one.

Use more than one image

An edit can take up to three images: image, image_2 and image_3, each an https link, a data URL or an upload's asset_id. The prompt calls them picture 1, picture 2 and picture 3. This dresses a person in a garment from a product photo, or puts your product into another photo:

{"model": "qwen-image/edit", "image": "https://example.com/woman.jpg", "image_2": "https://example.com/jacket.jpg",
 "prompt": "Dress the woman in picture 1 in the jacket from picture 2: the same mustard yellow corduroy, brown buttons and collar. Keep her face, hair, pose and the background of picture 1 unchanged."}

All the images together are at most 7 MiB, and the whole request body at most 10 MiB.

To put a logo on a product, send the logo as picture 2 and describe the finished print, its place, size, finish and light. "print the logo on the shoe" alone tends to come back pasted on top. The model keeps picture 2's look: a logo on a coloured tile comes back as that tile, a small printed badge, and a logo on a transparent background comes back as the mark alone.

{"model": "qwen-image/edit", "image": "https://example.com/sneaker.jpg", "image_2": "data:image/png;base64,iVBORw0KGgo...",
 "prompt": "The navy canvas sneaker in picture 1 has the logo from picture 2 printed on its outer side near the heel, small, about the size of a coin, in the logo's own colors. It looks like it came from the factory: matte, flat on the canvas, following the shoe's curve, in the same sunlight and shade as the canvas around it. Keep the shoe, laces, stitching and the background of picture 1 unchanged."}

Name the finish (printed, embroidered), not the printing process: words like "screen-printed" or "the texture shows through the ink" can turn the logo into large halftone dots.

Get a transparent background

Send "transparent_background": true with output_format png or webp, and the result comes back with its background removed: the main subject on transparency, ready to place on a page or a product listing. It costs the same as the edit.

Keep the photo's shape

An edit comes back in the shape of the image to edit (aspect_ratio auto, the default), as the model does on its own: a 3:2 photo comes back 1248x832 at 1K and 2048x1376 at 2K. Shapes between 1:2 and 2:1 are kept. Wider or taller ones come back at 2:1 or 1:2. Send 1:1, 16:9 or 9:16 to choose a shape instead. The model then re-frames the photo to fit.

Modes

Send mode to choose how the edit is made:

ModeWhat it does
fast4 steps. The quickest and cheapest.
maxThe full model at 50 steps. Slow.
detailDraws a 16:9 or 9:16 edit larger and shrinks it, for sharper faces. Costs about 16% more. Only for aspect_ratio 16:9 or 9:16 at resolution 1K, with one or two images. Anything else is refused.

Leave mode out for auto, which reads your prompt and picks per request: an edit about a person (their face, hair, skin, clothes or accessories) at 16:9 or 9:16, 1K, with one or two images takes detail. Every other edit takes fast (4 steps). If auto cannot read the prompt in time, it takes fast. Send steps instead of mode to set the count yourself, but not both: steps with any mode other than auto is refused. Each mode's price is in modes in GET /v1/models, and the finished generation's mode says which one ran.

Write the change the way the model reads it

The edit model follows the instruction forms its makers publish (the Qwen-Image prompt guide). A change worded another way can redraw more than you meant: "Move this car to a snowy road" redrew a close-up of a car door as a whole car, where "Replace the background with a snowy mountain road at dusk. Keep the red car, its position, its size in the frame and the camera angle unchanged." kept the close-up and changed only the background.

TaskWrite it as
Change the placeReplace the background with <the new place>. Keep <the subject>, its position, its size in the frame and the camera angle unchanged.
Swap an objectReplace <the object> with <the new one, its color, size and look>.
Add somethingAdd <what> <where>, with its color, size and position: Add a light-gray cat in the bottom-right corner, sitting and facing the camera.
Change a person's lookReplace the man's hat with a dark brown beret; keep his smile, short hair and gray jacket unchanged.
Change wordsReplace "250 g" with "500 g". The words go in double quotes.
Restore an old photoRestore and colorize the photo.
Use more than one imageName the picture each part comes from: Replace the jacket of the woman in picture 1 with the jacket in picture 2.

Photo limits

TypesJPEG, PNG or WebP, checked by the file's first bytes
SizeUp to 7 MiB
Pixels64 to 8192 a side, at most 16.7 megapixels, at most 8:1

Say what to keep as well as what to change: "Keep the mug's shape, color and printed logo unchanged."

Large files: upload first

  1. POST /v1/uploads with kind, mime, bytes and filename. The answer has asset_id, upload_url and upload_headers.
  2. PUT the file's bytes to upload_url with every header in upload_headers. The link is signed and works for 15 minutes.
  3. Send the asset_id as image, image_2 or image_3 in an edit.

TensorFactory doesn't keep your photos: an upload is deleted when the run that uses it ends, so upload the file again for each edit. An upload no run uses is deleted 30 minutes after it is made.

The API reference has each field.

On this page