live
MODEL IDbfl:flux@3.1-image

FLUX 3.1 Image

Black Forest Labs
by
Available with Zero Data Retention

FLUX 3.1 Image is Black Forest Labs' image generation and editing model, built for speed at every size from 1 MP up to native 4K. It keeps people and objects consistent across multiple references, edits locally through masks and bounding boxes while leaving the rest of the image untouched, and changes or translates text in its original lettering. It suits high-volume work such as product catalogs, virtual try-on, storyboards and key art.

FLUX 3.1 Image

Masked edits

How to aim a FLUX 3.1 Image edit with a mask: picking one of two identical objects, placing something new and putting a reference onto a product.

Introduction

A sentence names a thing. When the frame holds two of that thing, the sentence can only pick one by describing its position, and the model may read the position differently than you meant it.

inputs.maskImage picks it by pointing. You send a black and white image at the source's aspect ratio, white where the edit may happen and black where the image stays as it is, and FLUX 3.1 Image applies the instruction inside the white area.

A kitchen with a long white marble island and two identical matte white dome pendant lamps above it, with the masked area over the right lamp highlighted

A modern kitchen with a long white marble island across the lower half of the frame and two identical pendant lamps hanging above it, each a matte white metal dome on a thin black cord, one centered on the left third of the frame and one centered on the right third, both hanging at the same height in the upper half. Pale oak cabinets and a plain white wall behind, three bar stools tucked under the island. Soft daylight from a window out of frame on the left. Straight-on shot at standing height, 35mm lens. Photoreal kitchen interior photography, bright neutral palette.

Source and maskResult

The prompt says "the pendant lamp" and never says which, so the mask carries all of the targeting. That is what lets one instruction run across a whole catalog of room photos, with a mask drawn per photo.

This guide covers the request, picking one object out of several, placing something new, combining a mask with a reference, making a mask and when to leave it out.

The request

The mask goes in inputs.maskImage, next to the image it edits in inputs.referenceImages:

Try in Playground
import { createClient } from '@runware/sdk'

const client = await createClient({ apiKey: process.env.RUNWARE_API_KEY })

const [result] = await client.run({
  model: 'bfl:flux@3.1-image',
  positivePrompt: 'Change the pendant lamp to brushed brass with a warm satin finish. Keep its dome shape, its size, its cord and its height above the island unchanged, and keep everything else in the image exactly the same.',
  inputs: {
    referenceImages: [
      'https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-kitchen.jpg'
    ],
    maskImage: 'https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-kitchen.png'
  },
  width: 1248,
  height: 832
})
import asyncio
import os

from runware import Runware


async def main():
    async with Runware(api_key=os.environ["RUNWARE_API_KEY"]) as client:
        results = await client.run({
            "model": "bfl:flux@3.1-image",
            "positivePrompt": "Change the pendant lamp to brushed brass with a warm satin finish. Keep its dome shape, its size, its cord and its height above the island unchanged, and keep everything else in the image exactly the same.",
            "inputs": {
                "referenceImages": [
                    "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-kitchen.jpg"
                ],
                "maskImage": "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-kitchen.png"
            },
            "width": 1248,
            "height": 832
        })


asyncio.run(main())
curl https://api.runware.ai/v1 \
  -H "Authorization: Bearer $RUNWARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "taskType": "imageInference",
      "taskUUID": "6e2c9a41-3f7b-4d18-a5c0-8b4e1f7d2a93",
      "model": "bfl:flux@3.1-image",
      "positivePrompt": "Change the pendant lamp to brushed brass with a warm satin finish. Keep its dome shape, its size, its cord and its height above the island unchanged, and keep everything else in the image exactly the same.",
      "inputs": {
        "referenceImages": [
          "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-kitchen.jpg"
        ],
        "maskImage": "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-kitchen.png"
      },
      "width": 1248,
      "height": 832
    }
  ]'
runware run bfl:flux@3.1-image \
  positivePrompt="Change the pendant lamp to brushed brass with a warm satin finish. Keep its dome shape, its size, its cord and its height above the island unchanged, and keep everything else in the image exactly the same." \
  inputs.referenceImages.0=https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-kitchen.jpg \
  inputs.maskImage=https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-kitchen.png \
  width=1248 \
  height=832
{
  "taskType": "imageInference",
  "taskUUID": "6e2c9a41-3f7b-4d18-a5c0-8b4e1f7d2a93",
  "model": "bfl:flux@3.1-image",
  "positivePrompt": "Change the pendant lamp to brushed brass with a warm satin finish. Keep its dome shape, its size, its cord and its height above the island unchanged, and keep everything else in the image exactly the same.",
  "inputs": {
    "referenceImages": [
      "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-kitchen.jpg"
    ],
    "maskImage": "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-kitchen.png"
  },
  "width": 1248,
  "height": 832
}
Response
{
  "data": [
    {
      "taskType": "imageInference",
      "taskUUID": "6e2c9a41-3f7b-4d18-a5c0-8b4e1f7d2a93",
      "imageUUID": "b47d0e85-1a6c-4f29-9d3b-e5c8a2f61b07",
      "imageURL": "https://im.runware.ai/image/os/a14d18/ws/2/ii/b47d0e85-1a6c-4f29-9d3b-e5c8a2f61b07.jpg"
    }
  ]
}

Five rules govern the pair:

  • A mask needs a reference. inputs.maskImage without inputs.referenceImages is rejected, since there is nothing for it to point at.
  • It applies to the first reference. With several references, the image you are editing goes at the front of the array.
  • It has the first reference's aspect ratio. A mask more than 3% off that ratio is rejected. Draw it at the image's pixel size and the white area lands on the object you drew it over.
  • The output keeps the first reference's shape. width and height have to sit within 3% of its aspect ratio, so sending the source's own size, as above, keeps the result aligned with it pixel for pixel.
  • Nine references at most. The mask takes the tenth slot, so a masked request carries one reference fewer than an unmasked one.

Picking one object out of several

The same instruction on the same kitchen, sent without the mask:

The kitchen with two identical matte white dome pendants over the marble island

A modern kitchen with a long white marble island across the lower half of the frame and two identical pendant lamps hanging above it, each a matte white metal dome on a thin black cord, one centered on the left third of the frame and one centered on the right third, both hanging at the same height in the upper half. Pale oak cabinets and a plain white wall behind, three bar stools tucked under the island. Soft daylight from a window out of frame on the left. Straight-on shot at standing height, 35mm lens. Photoreal kitchen interior photography, bright neutral palette.

SourceWithout a mask

Without the mask the model has to decide which lamp "the pendant lamp" means, and here it changed both. Rewording to "the pendant on the right" is the other fix, and it holds only as long as every photo in the set has the lamps in the same arrangement. A mask works the same whatever the wording, which matters once the instruction is a template and the photos vary.

Placing something new

When the edit adds an object, the white area marks where it goes and how big it is. The instruction below asks for a framed print and says nothing about its position or size.

A hotel bedroom with a white-linen king bed, a gray upholstered headboard and brass reading lamps on oak bedside tables, with the masked area on the empty wall above the headboard highlighted

A hotel bedroom with a king bed made up in crisp white linen and a wide gray upholstered headboard across the lower half of the frame, a white oak bedside table with a small brass reading lamp on each side. The wall above the headboard is plain warm white and completely empty, from the top of the headboard to the ceiling. Soft daylight from a window out of frame on the right. Straight-on shot at standing height from the foot of the bed, 35mm lens, the bed centered. Photoreal hospitality photography, calm neutral palette.

Source and maskResult

The white area sets the object's size, so draw it as big as the object you want. The print fills the rectangle edge to edge, which makes the mask the layout decision and the prompt only has to describe the print and how it hangs. For a hotel that wants to preview artwork options across its rooms, the mask stays fixed per room photo and the prompt changes per piece.

Masks with a reference

A mask combines with more references, which is how a specific design lands on an exact spot of a product. The mask still applies to image 1, and image 2 supplies what goes inside it.

A woman's hand holding a black smartphone with a blank glossy screen in front of a blurred green park, with the masked area over the screen highlighted

A close-up of a woman's hand holding a black smartphone upright in the center of the frame, the screen facing the camera, switched off and glossy black, the phone filling the middle third of the frame width. A softly blurred city park with green trees behind. Soft daylight from the left, natural skin tones, a short neutral manicure. Straight-on shot at hand height, 85mm lens, shallow depth of field. Photoreal lifestyle product photography for an app store listing, fresh palette.

Source and maskResult
Built from 1 reference
  • App screen

The prompt assigns roles and leaves the screen to the reference: it never describes the ring or the cards, because image 2 already carries them. The mask places the screen and the reference fills it, while "a faint glass reflection" makes it read as a photographed display. One hand shot then serves every screen of an app store listing.

Try in Playground
import { createClient } from '@runware/sdk'

const client = await createClient({ apiKey: process.env.RUNWARE_API_KEY })

const [result] = await client.run({
  model: 'bfl:flux@3.1-image',
  positivePrompt: 'Show the app screen from image 2 on the display of the phone in image 1, filling the display edge to edge, with a faint glass reflection across it. Keep the hand, the phone body, the blurred park, the framing and the lighting unchanged.',
  inputs: {
    referenceImages: [
      'https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-phone.jpg',
      'https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/reference-app.jpg'
    ],
    maskImage: 'https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-phone.png'
  },
  width: 832,
  height: 1248
})
import asyncio
import os

from runware import Runware


async def main():
    async with Runware(api_key=os.environ["RUNWARE_API_KEY"]) as client:
        results = await client.run({
            "model": "bfl:flux@3.1-image",
            "positivePrompt": "Show the app screen from image 2 on the display of the phone in image 1, filling the display edge to edge, with a faint glass reflection across it. Keep the hand, the phone body, the blurred park, the framing and the lighting unchanged.",
            "inputs": {
                "referenceImages": [
                    "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-phone.jpg",
                    "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/reference-app.jpg"
                ],
                "maskImage": "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-phone.png"
            },
            "width": 832,
            "height": 1248
        })


asyncio.run(main())
curl https://api.runware.ai/v1 \
  -H "Authorization: Bearer $RUNWARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "taskType": "imageInference",
      "taskUUID": "d2f81b6a-4c37-4e90-8a15-3b9c7e0f5d42",
      "model": "bfl:flux@3.1-image",
      "positivePrompt": "Show the app screen from image 2 on the display of the phone in image 1, filling the display edge to edge, with a faint glass reflection across it. Keep the hand, the phone body, the blurred park, the framing and the lighting unchanged.",
      "inputs": {
        "referenceImages": [
          "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-phone.jpg",
          "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/reference-app.jpg"
        ],
        "maskImage": "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-phone.png"
      },
      "width": 832,
      "height": 1248
    }
  ]'
runware run bfl:flux@3.1-image \
  positivePrompt="Show the app screen from image 2 on the display of the phone in image 1, filling the display edge to edge, with a faint glass reflection across it. Keep the hand, the phone body, the blurred park, the framing and the lighting unchanged." \
  inputs.referenceImages.0=https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-phone.jpg \
  inputs.referenceImages.1=https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/reference-app.jpg \
  inputs.maskImage=https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-phone.png \
  width=832 \
  height=1248
{
  "taskType": "imageInference",
  "taskUUID": "d2f81b6a-4c37-4e90-8a15-3b9c7e0f5d42",
  "model": "bfl:flux@3.1-image",
  "positivePrompt": "Show the app screen from image 2 on the display of the phone in image 1, filling the display edge to edge, with a faint glass reflection across it. Keep the hand, the phone body, the blurred park, the framing and the lighting unchanged.",
  "inputs": {
    "referenceImages": [
      "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/source-phone.jpg",
      "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/reference-app.jpg"
    ],
    "maskImage": "https://assets.runware.ai/guides/bfl-flux-3-1-image/masked-edits/mask-phone.png"
  },
  "width": 832,
  "height": 1248
}
Response
{
  "data": [
    {
      "taskType": "imageInference",
      "taskUUID": "d2f81b6a-4c37-4e90-8a15-3b9c7e0f5d42",
      "imageUUID": "7a3e5c90-8b14-4d6f-a2e9-1c5f8b3d0e76",
      "imageURL": "https://im.runware.ai/image/os/a14d18/ws/2/ii/7a3e5c90-8b14-4d6f-a2e9-1c5f8b3d0e76.jpg"
    }
  ]
}

The order of the array is what makes this work. The phone is image 1 because the mask always lands on the first reference, and the screen is image 2 because it only supplies content.

Making a mask

Drop in your source image, paint over the area you want to change and download the mask. It comes out white on black at the source's own size, which is the format inputs.maskImage expects.

30
50%
100%

Drop an image here or browse

For a templated shot, where the product sits in the same place in every photo, draw the mask in code instead. A rounded rectangle over the known area is enough, as in this ImageMagick command for the phone mask above:

magick -size 832x1248 xc:black -fill white -draw "roundrectangle 240,238 594,988 36,36" mask-phone.png

Leave a small margin around the object. Its edge, its shadow and the point where it meets a surface sit just outside its outline, and the edit needs room to redraw them.

When to leave the mask out

A mask limits where the edit can happen, so it works against changes meant to touch the whole frame. A relight or a new season has to rebuild shadows and reflections everywhere, and a mask around one object stops them at its edge. Those edits belong in editing images.

When the target appears once and has a clear name, the instruction already finds it, and the mask only adds a file to maintain. When you need to move an object or place several at set coordinates, bounding boxes describe the positions directly.

Tips for best results

  1. Put the image you are editing first. The mask applies to the first reference, and there is no way to aim it at another.

  2. Match the first reference's aspect ratio. Draw the mask at that image's pixel size so the white area lands where you drew it.

  3. Send the source's own size. A masked edit keeps the first reference's shape, and width and height more than 3% off it are rejected.

  4. Keep naming the target. The mask chooses the area and the instruction still says what happens inside it.

  5. Size the area for a new object. An added object fills the white area, so its shape is the object's shape.

  6. Leave a margin. The edge, the shadow and the contact point need room just outside the object.

  7. Let the reference carry the design. With a mask and a reference, say what to take from image 2 and leave its contents undescribed.

  8. Count your references. Nine at most with a mask, ten without.