Skip to main content
Use 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.In Token management, create a token with Billing mode set to Per-call (按次计费), then select Create.
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 to flux-generation.json:

Save the result

The response contains data[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
The script prints 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-style size 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

Add input_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:
Multiple references work only through these JSON fields on this endpoint. For local files, up to eight references, a Python helper, and edit prompts, see FLUX.2 image editing.

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_ratio field instead of size. With the OpenAI Python SDK, pass it through extra_body.
  • Any ratio from 3:7 to 7:3 works, and the output stays at about one megapixel.
Common ratios and their approximate output: 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 a polling_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 same seed 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, try flux-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, with client.images.generate():
  • Set base_url to https://api.laozhang.ai/v1.
  • Pass model, prompt, and size as usual.
  • Put FLUX-specific fields such as width, height, and seed in extra_body.
The image URL is in 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.