POST /v1/images/generations and /v1/images/edits
The exact contract for Flux image generation and image edits: request fields, the streaming events, the response, headers and every error.
Generate an image from a prompt, or edit one with reference images. For a guided tour, see Make and edit images.
| Endpoint | Body | Status |
|---|---|---|
POST https://api.fluxrouter.ai/v1/images/generations | JSON | Live |
POST https://api.fluxrouter.ai/v1/images/edits | multipart form | Live |
Both take your Flux key as Authorization: Bearer sk-flux... (or x-api-key). Both need a paid, cleared plan, and the key's model allowlist must include the model you ask for.
Generations: request
| Field | Type | Required | Notes |
|---|---|---|---|
prompt | string | Yes | What to draw. |
model | string | No | An image model id. Leave it out for the default, flux-image. The list is on GET /v1/models with capability set to image. |
n | integer | No | How many images. Default 1. Each image is billed. |
size | string | No | Default 1024x1024. Most models make their own fixed size and ignore it. |
quality | string | No | Changes the price, not the request shape. |
response_format | string | No | Default b64_json. |
category | string | No | Standard (default), Plus, Pro or Ultra. Picks a model for that price class when you do not name one. |
max_price | number | No | The most you will pay, in US dollars, checked against the final price. Over it, the call answers 402 price_exceeds_max_price, returns no image and charges nothing. |
stream | boolean | No | true for server-sent events (below). |
partial_images | integer | No | With stream, how many rough previews to send first, from 0 to 3. Higher values are lowered to the maximum, not refused. |
A chat-shaped body works too: send messages with "tools": [{ "type": "image_generation" }] and no prompt, and the prompt is taken from the last user message.
Edits: request
A multipart/form-data body.
| Field | Required | Notes |
|---|---|---|
image[] (or image) | Yes | Between one and 4 reference images: PNG, JPEG or WebP. Each up to 10 MB, and up to 20 MB in total. |
prompt | Yes | The change to make. |
model | No | Default flux-image. Edits work on flux-image and flux-image-pro; other models answer 400 edit_unsupported. |
size, quality, response_format, category, max_price | No | As for generations. |
An edit always returns exactly one image, and does not stream.
Response
{
"created": 1790000000,
"data": [{ "b64_json": "iVBORw0KGgo..." }]
}
dataholds one entry per image, each withb64_json(orurl).An edit response also carries
modeland ausageobject that includes thecost.The response may carry other fields. Ignore any you do not use.
A generation response does not carry its cost. Use
max_priceto cap it, and see each call on your usage page.In an edit response,
usage.costis what the call cost, in US dollars, once the charge has landed.
Generation times out after 60 seconds, and an edit after 90 seconds. Image calls do not count against the shared per-minute limit for audio and search.
Streaming events
With "stream": true on a generation, the response is text/event-stream:
Event type | Carries |
|---|---|
image_generation.partial_image | partial_image_index and a rough b64_json. Only on models that support previews, and only when you set partial_images. |
image_generation.completed | data, shaped like the normal response, and the final b64_json |
error | An error object, when something fails after the stream has started |
The stream ends with data: [DONE]. Models without previews send only the completed event, so one client handles every model.
data: {"type":"image_generation.partial_image","created":1790000000,"partial_image_index":0,"b64_json":"..."}
data: {"type":"image_generation.completed","created":1790000000,"data":[{"b64_json":"..."}],"b64_json":"..."}
data: [DONE]
Errors
Most errors use the ability shape, {"error": {"message", "type", "code"}}. A credit refusal can arrive wrapped as {"detail": {"error": {...}}}; read detail.error when error is missing.
| Status | code | Meaning | Fix |
|---|---|---|---|
400 | none | prompt missing, or n not a whole number | Fix the body. |
400 | edit_unsupported | The model cannot edit. | Use flux-image or flux-image-pro. |
400 | invalid_reference_image | A reference image is the wrong type, too big, or there are too many. | Check the file limits above. |
400 | moderation_blocked | The prompt was refused (type image_generation_user_error). | Change the prompt. Retrying the same prompt fails again. |
401, 403 | permission_error | The key is missing or wrong, or its allowlist does not include this model. | Check the key and its allowlist on your keys page. |
402 | premium_locked | Images need a paid, cleared plan. Nothing was made or charged. | Upgrade in Billing. |
402 | price_exceeds_max_price | The final price was above your max_price. No image is returned and nothing is charged. | Raise max_price, or pick a cheaper model. |
403 | organization_must_be_verified | The chosen model is not available for this request. | Pick another model. |
404 | none | Images are not switched on for this account. | Contact support. |
502 | capability_unavailable | The image could not be made or priced. Not charged. | Retry shortly. |
Fixes in more detail are on Image problems.