Flux Kontext
FLUX Kontext Image Generation and Editing
Submit asynchronous FLUX Kontext image generation or image editing tasks. The API returns a task ID; poll the task endpoint for the generated image.
POST
Supported Models
Both models support text-to-image generation without reference images and image editing with reference images.
Authorizations
string
required
All endpoints require Bearer Token authentication.Get an API key from API Key Management, then add it to the request header:
Body
string
required
Model name:
flux-kontext-proflux-kontext-max
string
required
Text description of the image to generate or the edit to apply to the reference images.
array
Reference images for image editing. Publicly accessible image URLs and Base64 input are supported.
- Maximum: 4 images
- The output plus all reference images must not exceed 9 MP in total
temporarily unavailable dependency. When this happens, first check hotlink protection, access permissions, and expired signatures.string
default:"1:1"
Output aspect ratio. A pixel string such as
1024x1536 is also accepted, but Kontext maps it to the closest supported ratio rather than producing those exact pixel dimensions. Supported ratios:1:1(default)4:33:416:99:163:22:321:99:21
width or height; supplying either field causes the task to fail. Use size to control the aspect ratio. resolution has no effect for Kontext, whose output remains approximately 1 MP.
string
default:"png"
Output image encoding. Supported values:
png, jpeg, and webp.string
OpenAI-compatible response-shape field. It accepts only
url or b64_json and does not change the image encoding. When both fields are supplied, output_format takes priority.integer
default:"1"
Number of images generated per task. The only supported value is
1; submit multiple tasks concurrently if you need multiple images.integer
Random seed. Reuse the same seed and parameters for reproducible output; omit it to use a random seed.
boolean
default:"false"
Whether to enhance and rewrite the prompt before generation.Set this parameter explicitly to
false to disable prompt rewriting.integer
default:"2"
Safety tolerance from
0 to 6. Higher values are more permissive.Supported Aspect Ratios
Actual Output Dimensions
Usage Examples
Text-to-image generation
Image editing
Multiple reference images
Response
integer
Response status code.
array
Submission result array.
Retrieve the Result
PollGET /v1/tasks/{task_id} until the task reaches completed or failed. See the Task Status API for the complete response schema.
Task statuses:
A completed task includes one generated image:
data.result.images[0].url[0]. Its expiration is defined by the Unix timestamp in data.result.images[0].expires_at; download the image before that time.
Invalid parameters and failed tasks
Invalid model parameters do not produce a synchronous 4xx response. The submission still returns HTTP 200 with atask_id; keep polling until the task becomes failed, then read the specific reason from data.error.message. Failed tasks are fully refunded.
error.code is always task_failed; the specific reason is in error.message.
Notes
- Tasks are processed asynchronously. The submission response returns a
task_idfor polling. ndefaults to1, which is the only supported value.- Reference images may use publicly accessible image URLs or Base64 input.
- Up to 4 reference images are supported, subject to the 9 MP combined input-and-output limit.
- Set
prompt_upsampling: falseexplicitly to disable prompt rewriting. - Result URL expiration is determined by the
expires_atvalue returned in the task response. widthandheightcause the task to fail;resolutiondoes not change the approximately 1 MP output; a pixel-stringsizemaps to the closest supported ratio.- Invalid model parameters are returned asynchronously: poll until
failedand readdata.error.message.