Skip to main content
POST
/
img2img
Generate image from text and reference images (Flux Kontext Model)
curl --request POST \
  --url https://modelslab.com/api/v6/images/img2img \
  --header 'Content-Type: application/json' \
  --data '{
  "key": "<string>",
  "model_id": "flux-kontext-dev",
  "prompt": "<string>",
  "negative_prompt": "<string>",
  "init_image": "<string>",
  "init_image_2": "<string>",
  "num_inference_steps": 25,
  "strength": 0.5,
  "guidance": 10,
  "enhance_prompt": true,
  "width": 512,
  "height": 512,
  "samples": 1,
  "seed": 123,
  "base64": false,
  "webhook": "<string>",
  "track_id": "<string>",
  "temp": false
}'
{
  "status": "success",
  "generationTime": 123,
  "id": 123,
  "output": [
    "<string>"
  ],
  "proxy_links": [
    "<string>"
  ],
  "meta": {},
  "nsfw_content_detected": true
}
Text to image endpoint result

Request

Make a POST request to below endpoint and pass the required parameters as a request body.
curl
--request POST 'https://modelslab.com/api/v6/images/img2img' \

Body

json
{
  "key": "your_api_key",
  "init_image": "https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/livewire-tmp/SwogScBP0DtW8M90EDCMAjTYXdHFW4-metaMjhlNjgxMWE3MjY0NmY5ZmJjYTcyNGFjNWU3NTZlZGQuanBn-.jpg",
  "init_image_2": "https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/livewire-tmp/CGuHsNAUtB4Uif4J0tVTbAlEaICbB7-metaMzg4ZTdmZGRiNmQyZmYxY2JiMzk4ZTZkM2VjZDBmNTEuanBn-.jpg",
  "prompt": "a girl from image one holding the can from image two",
  "negative_prompt": "(worst quality:2), (low quality:2), (normal quality:2), (jpeg artifacts), (blurry), (duplicate), (morbid), (mutilated), (out of frame), (extra limbs), (bad anatomy), (disfigured), (deformed), (cross-eye), (glitch), (oversaturated), (overexposed), (underexposed), (bad proportions), (bad hands), (bad feet), (cloned face), (long neck), (missing arms), (missing legs), (extra fingers), (fused fingers), (poorly drawn hands), (poorly drawn face), (mutation), (deformed eyes), watermark, text, logo, signature, grainy, tiling, censored, nsfw, ugly, blurry eyes, noisy image, bad lighting, unnatural skin, asymmetry",
  "model_id": "flux-kontext-dev",
  "num_inference_steps": "28",
  "strength": "0.5",
  "guidance": "2.5",
  "enhance_prompt": null
}

Body

application/json
key
string
required

Your API Key used for request authorization.

model_id
string
default:flux-kontext-dev
required

The ID of the model. Must be 'flux-kontext-dev' for Flux Kontext model.

prompt
string
required

A text description of the things you want in the generated image, referencing elements from the input images.

init_image
string<uri>
required

URL of the primary reference image to use as a base for the generation.

negative_prompt
string

Items you don't want in the image. Helps exclude unwanted elements, artifacts, or styles from the generation.

init_image_2
string<uri>

URL of the secondary reference image to incorporate elements from. Optional for single-image workflows.

num_inference_steps
default:28

The number of denoising steps. Values typically range from 1 to 50. Can be provided as integer or string.

Required range: 1 <= x <= 50
strength
default:0.5

Controls how much the output image should resemble the input image. 0.0 means identical to input, 1.0 means completely different. Can be provided as number or string.

Required range: 0 <= x <= 1
guidance
default:2.5

Scale for classifier-free guidance. Higher values make the model follow the prompt more closely. Can be provided as number or string.

Required range: 0 <= x <= 20
enhance_prompt
boolean | null

Enhance prompts for better results. Set to null to use model defaults.

width
integer
default:512

The width of the output image in pixels. Maximum value is 1024.

Required range: x <= 1024
height
integer
default:512

The height of the output image in pixels. Maximum value is 1024.

Required range: x <= 1024
samples
integer
default:1

The number of images to be returned in response. Maximum value is 4.

Required range: x <= 4
seed
integer | null

Used to reproduce results. The same seed will generate the same image again. Pass null for a random number.

base64
boolean
default:false

Get response as a base64 string.

webhook
string<uri>

URL to receive a POST API call once image generation is complete.

track_id
string

This ID is returned in the response to the webhook API call and is used to identify the webhook request.

temp
boolean
default:false

Create a temporary image link valid for 24 hours.

Response

Flux Kontext Image to Image generation response

  • Option 1
  • Option 2
  • Option 3
status
enum<string>

Status of the image generation.

Available options:
success
generationTime
number

Time taken to generate the image in seconds.

id
integer

Unique identifier for the image generation request.

output
string<uri>[]

Array of generated image URLs.

Array of proxy image URLs.

meta
object

Metadata about the image generation including all parameters used.

nsfw_content_detected
boolean

Indicates if NSFW content was detected in the generated image.

I