flux-2-pro for most FLUX.2 work. Generation and editing share one JSON endpoint billed per call, and each result URL expires 10 minutes after generation, so download it right away.
All three models use the same request format.
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 examples use:Generate an image
This request creates a 1792×1024 landscape image and writes the response toflux-generation.json:
Save the result
The response containsdata[0].url, and that URL expires 10 minutes after the image is generated, so download it right away. FLUX returns only URLs, never b64_json. Save this script as save_images.py; it downloads every image in a response (it also decodes b64_json, which some other image models return):
save_images.py
Saved flux-robot-1.jpg. FLUX.2 returns JPEG unless you set output_format to png.
Generate with Python
Output size
Set the output size with an OpenAI-stylesize string or with width and height in pixels. Use one form, not both.
width and height must be multiples of 16 and at least 64 pixels, with no more than about 4 megapixels in total (for example, 2048×2048). Edits take the same size fields.
Edit an image
Addinput_image to the same JSON request to edit an image instead of starting from text alone. This minimal edit keeps the subject of a public image and replaces its background:
Parameters
Legacy compatibility: FLUX Kontext
flux-kontext-pro ($0.035 per call) and flux-kontext-max ($0.07 per call) remain available for existing integrations. They use the same endpoint, with these differences:
- They take an
aspect_ratiofield instead ofsize. With the OpenAI Python SDK, pass it throughextra_body. - Any ratio from
3:7to7:3works, and the output stays at about one megapixel.
For new generation or editing work, use FLUX.2.
Frequently asked questions
Do I need to poll for results like the BFL API?
No. The BFL API returns a task ID and apolling_url that you poll until the status is Ready. LaoZhang API waits for the image within the same request and returns it in data[0].url.
Give the client a generous timeout instead; the Python example uses 240 seconds. If the request passes through a reverse proxy or a serverless function, raise its timeout or execution limit as well, or the connection closes before the image is ready.
Why does the image URL stop working?
Result URLs expire 10 minutes after generation, the same lifetime BFL gives its own result links. Download each image on your server as soon as its request returns, store it in your own storage, and hand that address to your database or front end. In batch jobs, download each result as its request finishes instead of waiting for the whole batch, and keep concurrency low enough that downloads keep pace. An expired URL can’t be refreshed. Send the request again, which is billed as a new call.How do I get repeatable results?
Send the sameseed with the same model, prompt, and size. This helps when you iterate on one design.
How do I get accurate text and brand colors?
For text-heavy images such as posters, infographics, and UI mockups, tryflux-2-flex first; BFL positions it for text rendering and small details. Use flux-2-max when you need the highest quality and the strongest prompt following.
To match brand colors, put hex codes in the prompt, for example the mug is #FF5A1F. For complex scenes, you can also write the subject, background, lighting, and style as a JSON string and send it as the prompt.
Am I charged for failed requests?
No. FLUX.2 is billed per call: a request that returns an image is charged once, while a non-200 response, such as a parameter error or a moderation block, isn’t charged. A client timeout isn’t the same as a failure. The server may have finished the image and charged for it, so check call logs before you resend. Call logs are the final record of what you were charged.Can I use the OpenAI SDK?
Yes, withclient.images.generate():
- Set
base_urltohttps://api.laozhang.ai/v1. - Pass
model,prompt, andsizeas usual. - Put FLUX-specific fields such as
width,height, andseedinextra_body.
response.data[0].url; download it right away.
For edits, also use client.images.generate() and put input_image in extra_body; client.images.edit() accepts only one image. See the FLUX.2 image editing FAQ.
Related documentation
- FLUX.2 image editing: edit one image or combine up to eight references
- Choose an image generation 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
- Models and pricing in the console: prices available to your account
- Black Forest Labs: FLUX.2 overview: what each FLUX.2 variant is built for, hex color control, and structured prompts
- Black Forest Labs: API integration guidelines: BFL’s asynchronous polling flow and 10-minute result URLs