> ## 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.

# FLUX 3.1 Image

> Generate and edit high-resolution images up to 4K with fast and quality modes, painted masks, multi-reference inputs, and bounding boxes.

# FLUX 3.1 Image

Generate and edit images up to 4K at high throughput, with painted masks, up to 10 reference images, and bounding boxes for layout and local edits.

> [card] [Edit and control](https://docs.bfl.ml/flux_3_1/flux31_image_edit.md)
>
> Steer edits with written instructions, painted masks, and multi-reference inputs.

> [card] [Bounding boxes](https://docs.bfl.ml/flux_3_1/flux31_image_bounding_boxes.md)
>
> Author layouts and move, replace, or remove elements with structured `bounding_boxes`.

> [card] [4K and custom sizing](#sizing)
>
> Pick `1MP` to `16MP`, video frames (`hd` to `uhd`), or exact pixel dimensions without a divisible-by-16 constraint.

> [card] [Web grounding](#web-grounding)
>
> Pull real-world references for named subjects, landmarks, and species with `grounding`.

## Quickstart

Set `BFL_API_KEY` to a key from the [BFL dashboard](https://dashboard.bfl.ai), then submit a prompt:

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://api.bfl.ai/v1/flux-3.1-image",
    headers={"x-key": os.environ["BFL_API_KEY"]},
    json={
        "prompt": "Ultra-wide architectural blue-hour photograph of a monolithic concrete thermal pool cantilevered over a Swiss Alpine valley, soft steam rising off emerald water, medium-format film",
        "aspect_ratio": "21:9",
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

```bash cURL theme={null}
curl --fail-with-body https://api.bfl.ai/v1/flux-3.1-image \
  -H "x-key: $BFL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Ultra-wide architectural blue-hour photograph of a monolithic concrete thermal pool cantilevered over a Swiss Alpine valley, soft steam rising off emerald water, medium-format film",
    "aspect_ratio": "21:9"
  }'
```

Poll the returned `polling_url` until `status` is `Ready`:

```bash cURL theme={null}
curl "$POLLING_URL" -H "x-key: $BFL_API_KEY"
```

> [!WARNING]
>
> When `status` is `Ready`, download the image from `result.sample` right away because the signed URL expires after **1 hour**.

> [accordion] Complete clients: submit, poll, and save
>
> Each client submits the Quickstart prompt, polls until the task finishes, and saves the image. The Python `generate()` helper is used in the examples across the FLUX 3.1 Image docs. The cURL client requires `jq`.
>
> ```python Python theme={null}
> import os
> import time
> import requests
>
> API_KEY = os.environ["BFL_API_KEY"]
>
>
> def generate(payload, name="flux31_image"):
>     submit = requests.post(
>         "https://api.bfl.ai/v1/flux-3.1-image",
>         headers={"x-key": API_KEY},
>         json=payload,
>         timeout=60,
>     )
>     submit.raise_for_status()
>     polling_url = submit.json()["polling_url"]
>
>     while True:
>         time.sleep(1.0)
>         result = requests.get(polling_url, headers={"x-key": API_KEY}, timeout=60).json()
>         if result["status"] not in ("Pending", "Reasoning", "Generating"):
>             break
>     if result["status"] != "Ready":
>         raise RuntimeError(result)
>
>     ext = "png" if payload.get("output_format") == "png" else "jpg"
>     image = requests.get(result["result"]["sample"], timeout=120)
>     image.raise_for_status()
>     with open(f"{name}.{ext}", "wb") as f:
>         f.write(image.content)
>     return f"{name}.{ext}"
>
>
> generate({
>     "prompt": "Ultra-wide architectural blue-hour photograph of a monolithic concrete thermal pool cantilevered over a Swiss Alpine valley, soft steam rising off emerald water, medium-format film",
>     "aspect_ratio": "21:9",
> })
> ```
>
> ```javascript JavaScript theme={null}
> // Node.js 18+
> import { writeFile } from "node:fs/promises";
>
> const headers = { "x-key": process.env.BFL_API_KEY, "Content-Type": "application/json" };
>
> const submit = await fetch("https://api.bfl.ai/v1/flux-3.1-image", {
>   method: "POST",
>   headers,
>   body: JSON.stringify({
>     prompt: "Ultra-wide architectural blue-hour photograph of a monolithic concrete thermal pool cantilevered over a Swiss Alpine valley, soft steam rising off emerald water, medium-format film",
>     aspect_ratio: "21:9",
>   }),
> });
> if (!submit.ok) throw new Error(await submit.text());
> const { polling_url } = await submit.json();
>
> let result;
> do {
>   await new Promise((resolve) => setTimeout(resolve, 1000));
>   const poll = await fetch(polling_url, { headers });
>   if (!poll.ok) throw new Error(await poll.text());
>   result = await poll.json();
> } while (["Pending", "Reasoning", "Generating"].includes(result.status));
> if (result.status !== "Ready") throw new Error(JSON.stringify(result));
>
> const image = await fetch(result.result.sample);
> if (!image.ok) throw new Error(`Download failed: ${image.status}`);
> await writeFile("flux31_image.jpg", Buffer.from(await image.arrayBuffer()));
> ```
>
> ```bash cURL theme={null}
> POLLING_URL=$(curl -sS --fail-with-body https://api.bfl.ai/v1/flux-3.1-image \
>   -H "x-key: $BFL_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "prompt": "Ultra-wide architectural blue-hour photograph of a monolithic concrete thermal pool cantilevered over a Swiss Alpine valley, soft steam rising off emerald water, medium-format film",
>     "aspect_ratio": "21:9"
>   }' | jq -er .polling_url)
>
> while true; do
>   RESULT=$(curl -sS --fail-with-body "$POLLING_URL" -H "x-key: $BFL_API_KEY")
>   STATUS=$(echo "$RESULT" | jq -er .status)
>   [[ "$STATUS" =~ ^(Pending|Reasoning|Generating)$ ]] || break
>   sleep 1
> done
>
> if [ "$STATUS" = "Ready" ]; then
>   curl -sS --fail-with-body -o flux31_image.jpg "$(echo "$RESULT" | jq -er .result.sample)"
> else
>   echo "$RESULT" >&2
>   exit 1
> fi
> ```

## Sizing

By default, FLUX 3.1 Image chooses an aspect ratio and resolution automatically from your prompt or first input image. Use the controls below to pick a preset or exact pixel size, or set both `aspect_ratio` and `resolution` to `match_first_image` on edits to keep the dimensions of `images[0]` (within the 0.25 to 16.82 MP bounds).

| Control | Accepted values | Notes |
| - | - | - |
| `aspect_ratio` | `auto`, `match_first_image`, `21:9`, `2:1`, `16:9`, `3:2`, `7:5`, `4:3`, `5:4`, `1:1`, `4:5`, `3:4`, `5:7`, `2:3`, `9:16`, `1:2`, `9:21` | Ignored when `width` and `height` are set |
| `resolution` | `auto`, `match_first_image`, `1MP`, `2MP`, `4MP`, `8MP`, `12MP`, `16MP`, `1k`, `2k`, `4k`, `hd` (1280×720), `fhd` (1920×1080), `qhd` (2560×1440), `uhd` (3840×2160) | `1k`/`2k`/`4k` match the pixel area of a 1024/2048/4096 square (`4k` is 16.8 MP). Video frames set a 16:9 frame; add `aspect_ratio: "9:16"` for vertical frames |
| `width` and `height` | Set both together; 0.25 to 16.82 megapixels, min side 177 px, within an 8:1 aspect ratio | Any exact pixel size within bounds with no divisible-by-16 rule; overrides `aspect_ratio` and `resolution` |

## Quality and speed

Set `mode` to trade off maximum detail against faster, higher-volume generation. It defaults to `"quality"`.

| Mode | Best for |
| - | - |
| `"quality"` (default) | Typography, fine detail, multi-reference consistency, and 4K outputs |
| `"fast"` | High-volume generation and editing, interactive previews, and latency-sensitive pipelines |

> [tab] Handwritten notes (2MP)
>
> ![Antique botanical field notebook with pressed edelweiss generated in fast mode at 2MP](https://cdn.sanity.io/images/2gpum2i6/production/42188e32ee759c677fa2c72701e318c1a9ac5e4f-1732x1154.webp)
>
> mode: "fast"
>
> ![Antique botanical field notebook with pressed edelweiss generated in quality mode at 2MP](https://cdn.sanity.io/images/2gpum2i6/production/a4bf76b128453875448017158fdb8c8021e72ea3-1732x1154.webp)
>
> mode: "quality"

> [tab] 4-story cutaway (4K)
>
> ![Isometric cutaway of a Japanese townhouse generated in fast mode at 4K](https://cdn.sanity.io/images/2gpum2i6/production/0ca416e53e265402693a68a781c2f0e4b6349bf2-1800x1198.webp)
>
> mode: "fast"
>
> ![Isometric cutaway of a 4-story Japanese townhouse generated in quality mode at 4K](https://cdn.sanity.io/images/2gpum2i6/production/1d1f410dea5fcd983f6977cf02aab6bd5b560386-1800x1198.webp)
>
> mode: "quality"

## Web grounding

Use `grounding` to control whether FLUX 3.1 Image performs web lookups for real-world references such as landmarks, species, and named objects. It defaults to `"off"`.

| Value | Behavior |
| - | - |
| `"off"` (default) | Never perform web lookups |
| `"auto"` | The model decides per request whether to look up references |
| `"force"` | Always attempt web lookups before generating (falls back gracefully if lookup fails) |

```python Python theme={null}
generate({
    "prompt": "Editorial blue-hour photograph of the 2024 Paris Olympic cauldron floating above the Tuileries Garden basin at dusk, warm golden light reflecting in the calm water with the Louvre pavilion visible in the background",
    "aspect_ratio": "3:2",
    "grounding": "force",
}, name="paris_cauldron")
```

![Abstract gold metal flame sculpture floating above a rectangular reflecting pool when grounding is off](https://cdn.sanity.io/images/2gpum2i6/production/43b622f05af209c658b25a45b93a54f35711c9c5-1732x1154.webp)

grounding: "off" (invents an abstract metal flame sculpture)

![Real 2024 Paris Olympic hot-air balloon cauldron floating glowing above the Tuileries Garden basin at dusk with grounding forced](https://cdn.sanity.io/images/2gpum2i6/production/d148ef0ef1da39f889bfe11f9f6ffe1393db8b94-1732x1154.webp)

grounding: "force" (matches the real 2024 Paris Olympic hot-air balloon cauldron)

## Examples

Every image below was generated with FLUX 3.1 Image:

Previous clip

Next clip

## Limits and responses

| Constraint | Value |
| - | - |
| Output area (`width` × `height`) | 0.25 to 16.82 megapixels, minimum side 177 px, within an 8:1 aspect ratio |
| Reference images (`images`) | Up to 10 images (20 MB max each, URL or base64) |
| Bounding boxes (`bounding_boxes`) | 1 to 32 boxes per request using normalized 0 to 1 coordinates (`[y_min, x_min, y_max, x_max]`); see [Bounding boxes](https://docs.bfl.ml/flux_3_1/flux31_image_bounding_boxes.md) for layout and edit fields |
| Output format (`output_format`) | `"jpeg"` (default) or `"png"` |
| Moderation (`safety_tolerance`) | `0` (strictest) to `4`, default `2` |

Without a webhook, each submit returns `id` and `polling_url` to poll directly. When you pass `webhook_url` (and optional `webhook_secret`), submit returns `status: "processing"` without a `polling_url` and delivers the result to your webhook instead.

| Status | Next step |
| - | - |
| `Pending`, `Reasoning`, `Generating` | Keep polling `polling_url` |
| `Ready` | Download `result.sample` within 1 hour |
| `Request Moderated`, `Content Moderated` | Input or output failed moderation; adjust the prompt or input images before resubmitting |
| `Task not found` | Check the task ID and `polling_url`, or resubmit if the task expired |
| `Error` | Inspect the response body; resubmit if the failure was transient |

See the [API reference](https://docs.bfl.ml/api-reference/utility/generate-an-image-with-flux-3-1.md) for the full schema, [Errors](https://docs.bfl.ml/api_integration/errors.md) for shared HTTP codes (`402`, `422`, `429`), and [Integration guidelines](https://docs.bfl.ml/api_integration/integration_guidelines.md) for production retry patterns.

## Keep exploring

> [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 for `POST /v1/flux-3.1-image`.

> [card] [Prompting guide](https://docs.bfl.ml/guides/prompting_summary.md)
>
> Structure prompts for lighting, camera framing, typography, and edits.

> [card] [Try in Playground](https://playground.bfl.ai)
>
> Run FLUX 3.1 Image in your browser without writing code.

> [card] [Pricing](https://docs.bfl.ml/quick_start/pricing.md)
>
> Compare resolution tiers and billing across BFL endpoints.


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