flux/kontext-pro/image-to-image
Model Overview
An image-to-image model that modifies only what the prompt instructs, leaving the rest of the image untouched.
flux/kontext-pro/image-to-image
Format: JPEG, PNG Image size can't be set directly — only a preset aspect ratio can be chosen. Default aspect ratio and size: 16:9, 1184x880 (well, not quite 16:9)
Setup your API Key
If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.
API Schema
The CFG (Classifier Free Guidance) scale is a measure of how close you want the model to stick to your prompt when looking for a related image to show you.
The safety tolerance level for the generated image. 1 being the most strict and 5 being the most permissive.
2
Possible values: The format of the generated image.
jpeg
Possible values: The aspect ratio of the generated image.
16:9
Possible values: The text prompt describing the content, style, or composition of the image to be generated.
Number of image variations to generate. Each image is a different attempt to combine the reference images (from the image_url parameter) according to the prompt.
1
The same seed and the same prompt given to the same version of the model will output the same image every time.
One or more image URLs used as visual references. The model merges them into a single image following the prompt instructions.
POST /v1/images/generations HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 204
{
"model": "flux/kontext-pro/image-to-image",
"guidance_scale": 1,
"safety_tolerance": "2",
"output_format": "jpeg",
"aspect_ratio": "16:9",
"prompt": "text",
"num_images": 1,
"seed": 1,
"image_url": "https://example.com"
}
No content
Quick Example
Let's generate a new image using the one from the flux/dev Quick Example as a reference — and make a simple change to it with a prompt.
import requests
import json # for getting a structured output with indentation
# URL of the reference picture
img_url = "https://zovi0.github.io/public_misc/flux-dev-t-rex.png"
def main():
response = requests.post(
"https://api.aimlapi.com/v1/images/generations",
headers={
# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
"Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
"Content-Type": "application/json",
},
json={
"prompt": "Add a bird to the foreground of the photo.",
"model": "flux/kontext-pro/image-to-image",
"image_url": img_url,
}
)
# response.raise_for_status()
data = response.json()
print(json.dumps(data, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()


Example #2: Combine two images
This time, we’ll pass two images to the model: our dinosaur and a solid blue mug. We'll ask the model to place the dinosaur onto the mug as a print.
import requests
import json # for getting a structured output with indentation
# URLs of two reference pictures
images = ["https://zovi0.github.io/public_misc/flux-dev-t-rex.png", "https://zovi0.github.io/public_misc/blue-mug.jpg"]
def main():
response = requests.post(
"https://api.aimlapi.com/v1/images/generations",
headers={
# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
"Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
"Content-Type": "application/json",
},
json={
"prompt": "Place this image with the t-rex on this mug from the second image as a print. Make it look fit and natural.",
"model": "flux/kontext-pro/image-to-image",
"image_url": images
}
)
data = response.json()
print(json.dumps(data, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()

"Place this image with the t-rex on this mug from the second image as a print. Make it look fit and natural."
Last updated
Was this helpful?