> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bfl.ml/llms.txt
> Use this file to discover all available pages before exploring further.

# Bounding boxes with FLUX 3.1 Image

> Place elements in a layout or move, replace, and remove objects in an image with structured bounding_boxes.

FLUX 3.1 Image

# Bounding boxes

Pass 1 to 32 entries in `bounding_boxes` to place subjects and headlines in a layout, or to move, replace, and remove objects in an existing image.

Each box takes a unique `id` (letters, digits, and `_`, starting with a letter), `[y_min, x_min, y_max, x_max]` coordinates from `0` to `1`, and an optional `desc`. Reference each box inside `prompt` in angle brackets (`<title_1>`, `<arch_1>`):

```python Python theme={null}
generate({
    "prompt": 'Exhibition poster with headline "MONOLITH" <title_1> above a fluted terracotta arch <arch_1> on warm bone paper.',
    "bounding_boxes": [
        {"id": "title_1", "bbox": [0.06, 0.08, 0.22, 0.92], "desc": 'Bold charcoal sans-serif headline reading "MONOLITH".'},
        {"id": "arch_1", "bbox": [0.26, 0.20, 0.78, 0.80], "desc": "Fluted matte terracotta architectural arch."},
    ],
    "aspect_ratio": "4:5",
}, name="poster_layout")
```

## Box Studio

Try drawing boxes on a preset, a blank canvas, or your own image (files stay in your browser) to generate a request payload:

## Edit box by box

When `images` is set, use `from`, `src_bbox`, and `tgt_bbox` instead of `bbox`. `src_bbox` uses the input image (`ref_image_0` for `images[0]`, `ref_image_1` for `images[1]`) and `tgt_bbox` uses the output frame:

| Operation | `from` | `src_bbox` | `tgt_bbox` | Result |
| - | - | - | - | - |
| Keep | `"ref_image_0"` | Source box | Same box | Anchors the object in place |
| Move or resize | `"ref_image_0"` | Source box | New box | Relocates or rescales the object |
| New or replace | `"target"` | Omit | Target box | Generates `desc` inside `tgt_bbox` |
| Remove | `"ref_image_0"` | Source box | `null` | Clears the object and fills in the background |

Omit `src_bbox` when `from` is `"target"`, since sending both returns HTTP `422`.

## Localize a layout

Reuse the text boxes from a layout generation to swap titles, dates, and venues across languages while anchoring the terracotta arch (`arch_1`) in place:

> [accordion] Full Python script: generate and localize
>
> Both steps use the [`generate()` helper](https://docs.bfl.ml/flux_3_1/flux31_image_overview#quickstart):
>
> ```python Python theme={null}
> import base64
> from pathlib import Path
>
> # 1. Generate the base poster with bounding boxes
> boxes = [
>     {"id": "paper_1", "bbox": [0.0, 0.0, 1.0, 1.0], "desc": "Warm off-white textured bone print paper filling the full frame, no border."},
>     {"id": "title_1", "bbox": [0.06, 0.08, 0.22, 0.92], "desc": 'Bold geometric sans-serif headline reading "MONOLITH" in deep charcoal ink.'},
>     {"id": "arch_1", "bbox": [0.26, 0.20, 0.78, 0.80], "desc": "Monumental fluted matte terracotta architectural arch sculpture lit from the upper left."},
>     {"id": "dates_1", "bbox": [0.84, 0.08, 0.93, 0.44], "desc": 'Clean medium-weight sans-serif typography reading "DEC 03 - FEB 18" in charcoal.'},
>     {"id": "venue_1", "bbox": [0.84, 0.56, 0.93, 0.92], "desc": 'Clean medium-weight sans-serif typography reading "BASEL PAVILION" right-aligned in charcoal.'},
> ]
> base_poster = generate({
>     "prompt": (
>         'Minimalist architectural exhibition poster on warm textured bone paper <paper_1>. '
>         'Large bold deep-charcoal grotesque headline reading "MONOLITH" <title_1> spans the top, '
>         'a sculpted fluted terracotta architectural arch <arch_1> stands prominently in the center, '
>         'a crisp exhibition date block reading "DEC 03 - FEB 18" <dates_1> sits at lower left, '
>         'and a small venue credit reading "BASEL PAVILION" <venue_1> sits at lower right.'
>     ),
>     "bounding_boxes": boxes,
>     "aspect_ratio": "4:5",
>     "resolution": "2MP",
> }, name="monolith_en")
>
> # 2. Reuse the same coordinates to create regional editions
> poster_b64 = "data:image/jpeg;base64," + base64.b64encode(Path(base_poster).read_bytes()).decode("ascii")
>
> editions = [
>     ("fr", "French", "MONOLITHE", "03 DÉC - 18 FÉV", "PAVILLON PARIS"),
>     ("es", "Spanish", "MONOLITO", "03 DIC - 18 FEB", "PABELLÓN MADRID"),
>     ("ja", "Japanese", "モノリス", "12月3日 - 2月18日", "東京ギャラリー"),
> ]
>
> for code, lang, title, dates, venue in editions:
>     generate({
>         "prompt": (
>             f'In <ref_image_0>, localize the poster copy into {lang}: '
>             f'change the top headline to read "{title}" <title_1>, '
>             f'change the bottom-left date to read "{dates}" <dates_1>, '
>             f'and change the bottom-right venue to read "{venue}" <venue_1> '
>             'in deep charcoal sans-serif lettering. Keep the warm bone paper '
>             'and sculpted fluted terracotta arch <arch_1> completely unchanged.'
>         ),
>         "images": [poster_b64],
>         "bounding_boxes": [
>             {"id": "title_1", "from": "target", "tgt_bbox": [0.06, 0.08, 0.22, 0.92], "desc": f'Bold deep-charcoal sans-serif headline reading "{title}".'},
>             {"id": "dates_1", "from": "target", "tgt_bbox": [0.84, 0.08, 0.93, 0.44], "desc": f'Clean medium-weight charcoal sans-serif text reading "{dates}".'},
>             {"id": "venue_1", "from": "target", "tgt_bbox": [0.84, 0.56, 0.93, 0.92], "desc": f'Clean medium-weight charcoal sans-serif text reading "{venue}" right-aligned.'},
>             {"id": "arch_1", "from": "ref_image_0", "src_bbox": [0.26, 0.20, 0.78, 0.80], "tgt_bbox": [0.26, 0.20, 0.78, 0.80], "desc": "Monumental fluted matte terracotta architectural arch sculpture."},
>         ],
>         "resolution": "match_first_image",
>         "aspect_ratio": "match_first_image",
>     }, name=f"monolith_{code}")
> ```

## Tips and helpers

* Rough proportions are enough; give each box a shape that broadly fits the subject so the model has room to compose naturally.
* Give every headline or date line its own box and quote the exact wording inside `desc` so letters stay crisp inside their own region without overlapping adjacent artwork.
* Send the `aspect_ratio` (or `match_first_image`) that your boxes were authored for, because coordinates scale with the output frame.
* Boxes guide layout and placement rather than locking pixels. Use a [painted mask](https://docs.bfl.ml/flux_3_1/flux31_image_edit.md#painted-masks) when you need pixels outside the edited region restored from `images[0]`.

Convert pixel coordinates from an image into `[y_min, x_min, y_max, x_max]`:

```python Python theme={null}
def to_bbox(left, top, right, bottom, width, height):
    return [
        round(top / height, 3),
        round(left / width, 3),
        round(bottom / height, 3),
        round(right / width, 3),
    ]

to_bbox(384, 108, 1536, 972, 1920, 1080)  # [0.1, 0.2, 0.9, 0.8]
```

## Keep exploring

> [card] [Edit and control](https://docs.bfl.ml/flux_3_1/flux31_image_edit.md)
>
> Compare instructions, painted masks, reference images, and boxes on one source photo.

> [card] [API reference](https://docs.bfl.ml/api-reference/utility/generate-an-image-with-flux-3-1.md)
>
> Full request schema, field constraints, and response codes.

> [card] [Overview](https://docs.bfl.ml/flux_3_1/flux31_image_overview.md)
>
> Quickstart client, sizing options, 4K zoom inspector, and web grounding.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.