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
Bearer key
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.
2Possible values: The format of the generated image.
jpegPossible values: The aspect ratio of the generated image.
16:9Possible 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.
1The 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.
Successfully generated image
async function main() {
const response = await fetch('https://api.aimlapi.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'flux/kontext-pro/image-to-image',
prompt: "Add a crown to the T-rex's head.",
image_url: 'https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png',
}),
});
const data = await response.json();
console.log(JSON.stringify(data, null, 2));
}
main();Successfully generated image
{
"status": "text",
"prompt": [
"text"
],
"model": "text",
"model_owner": "text",
"tags": {
"ANY_ADDITIONAL_PROPERTY": null
},
"num_returns": 1,
"args": {
"model": "text",
"prompt": "text",
"n": 1,
"steps": 1,
"size": "text"
},
"subjobs": [],
"output": {
"choices": [
{
"image_base64": "text"
}
]
}
}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
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={
"model": "flux/kontext-pro/image-to-image",
"image_url": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png", # URL of the reference picture
"prompt": "Add a bird to the foreground of the photo.",
}
)
data = response.json()
print(json.dumps(data, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()const response = await fetch('https://api.aimlapi.com/v1/images/generations', {
method: 'POST',
headers: {
// Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'flux/kontext-pro/image-to-image',
prompt: 'Add a bird to the foreground of the photo.',
image_url: 'https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/t-rex.png',
}),
});
const data = await response.json();
console.log(JSON.stringify(data, null, 2));

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
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": [ # URLs of two reference pictures
"https://zovi0.github.io/public_misc/flux-dev-t-rex.png",
"https://zovi0.github.io/public_misc/blue-mug.jpg"
]
}
)
data = response.json()
print(json.dumps(data, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()const main = async () => {
const response = await fetch('https://api.aimlapi.com/v1/images/generations', {
method: 'POST',
headers: {
Authorization: 'Bearer <YOUR_API_KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'flux/kontext-pro/text-to-image',
prompt: 'Place this image with the t-rex on this mug from the second image as a print. Make it look fit and natural.',
image_url: [ // URLs of two reference pictures
'https://zovi0.github.io/public_misc/flux-dev-t-rex.png',
'https://zovi0.github.io/public_misc/blue-mug.jpg'
],
}),
}).then((res) => res.json());
console.log(response);
};
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?




