Start with
flux-2-pro. Black Forest Labs recommends flux-2-max for the highest-precision edits and flux-2-flex for fine-grained control, such as text rendering and small details. All three models take the same request.
Before you start
1
Create an API key
FLUX.2 models are billed per call. In Token management, create a key (or edit an existing one) and set Billing mode (计费模式) to Usage first (按量优先, recommended) or Per-call (按次计费). A Usage first key can call both per-call and usage-based models; a Per-call key calls only per-call models.Keep the key in a server-side environment variable.

2
Set up your environment
Export the key and install
requests, which the Python example uses:3
Save the download script
Save this script as
save_images.py. The cURL examples run it on the response file to download every image. FLUX returns only URLs; the script also decodes b64_json, which some other image models return:save_images.py
Edit an image
Addinput_image to a generation request to turn it into an edit. Replace the URL with a publicly accessible image:
Saved flux-edit-1.png. The reference URL is fetched during the request, so it must load without a login, cookies, or bot checks.
Edit a local file
To edit a file on your machine, send it as a data URL whose MIME type matches the file, such asdata:image/png;base64,... for a PNG. Passing the body through a heredoc keeps a large image out of the command line:
Combine reference images
Addinput_image_2 through input_image_8 for more references, and refer to them in the prompt as image 1, image 2, and so on, in field order. This example reads three PNG files from the current directory:
Edit with Python
This script accepts one to eight references, turns local files into data URLs, passes public URLs through unchanged, and saves the result as soon as the request returns:Parameters
Set the output size with either
size or width and height, not both. The FLUX.2 generation guide lists the common size values.
Handle the response
The response returns one image asdata[0].url. FLUX doesn’t return b64_json, so don’t send response_format. The link expires 10 minutes after the image is generated; download it as soon as the request returns, especially in batch jobs.
The image is JPEG unless you set output_format to png.
Prompt tips
- Refer to each source as image 1, image 2, image 3, and so on, in field order.
- Name the elements that must be preserved from each reference, such as a logo, a face, or a product color.
- Say that the output should be one coherent image.
- Say what to avoid, such as a collage, split screen, borders, or labels.
Errors and billing
- HTTP 400: check the field names, the number of references, and the output size.
- Field names:
input_image, theninput_image_2and up. - Number of references: at most 8.
- Output size: multiples of 16, at least 64 pixels, up to about 4 MP, set with
sizeor withwidthandheight.
- Field names:
- A reference can’t be loaded: the URL must be public. Otherwise send the file as a data URL.
- The result link no longer works: it expired 10 minutes after generation. Run the request again and download the result immediately.
- HTTP 401: check the key and the
Authorization: Bearerheader. - HTTP 429, 5xx, or a timeout: retry with backoff. After a timeout, check call logs before resending, so you don’t pay twice.
Legacy FLUX Kontext models
flux-kontext-pro and flux-kontext-max remain in the catalog for existing integrations. They use an aspect_ratio field instead of size; the legacy section of the generation guide covers them. Build new edits on FLUX.2.
FAQ
Can I edit only part of an image?
Yes, by describing it. The request has no mask field, so name the element to change in the prompt and say what must stay the same.Does an edit cost more than a generation?
No. FLUX.2 is billed per call, so an edit costs the same per-call price as a generation, whether you send one reference or eight and whatever the output size. Check call logs for the actual charge.Do editing and generation use the same model?
Yes.flux-2-pro, flux-2-flex, and flux-2-max handle both. A request with input_image is an edit; without it, the request generates a new image, as shown in FLUX.2 image generation.
Can I edit with the OpenAI SDK’s images.edit()?
Only for single-image edits. images.edit() uploads multipart form data to /v1/images/edits, which takes one image and can’t combine references.
Use client.images.generate() instead, and put input_image (plus the numbered fields for more references) in extra_body as public URLs or data URLs. The Python helper on this page does the same with requests.
Related documentation and sources
- FLUX.2 image generation — text-to-image requests, output sizes, and legacy Kontext models
- Choose an image API — compare FLUX.2 with other image models
- Images API reference — shared request and response format
- Model and pricing catalog — current FLUX prices and groups
- Call logs — check the model and charge for each request
- Black Forest Labs: FLUX.2 image editing — multi-reference editing, reference limits, and result URL lifetime
- Black Forest Labs: FLUX.2 overview — what each FLUX.2 variant is built for