flux/kontext-pro/image-to-image

This documentation is valid for the following list of our models:

  • 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.

Model
Properties of Generated Images

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

post
Authorizations
Body
modelundefined · enumRequiredPossible values:
guidance_scalenumber · min: 1 · max: 20Optional

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.

safety_tolerancestring · enumOptional

The safety tolerance level for the generated image. 1 being the most strict and 5 being the most permissive.

Default: 2Possible values:
output_formatstring · enumOptional

The format of the generated image.

Default: jpegPossible values:
aspect_ratiostring · enumOptional

The aspect ratio of the generated image.

Default: 16:9Possible values:
promptstring · max: 4000Required

The text prompt describing the content, style, or composition of the image to be generated.

num_imagesnumber · min: 1 · max: 4Optional

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.

Default: 1
seedinteger · min: 1Optional

The same seed and the same prompt given to the same version of the model will output the same image every time.

image_urlany ofRequired

One or more image URLs used as visual references. The model merges them into a single image following the prompt instructions.

string · uriOptional
or
string · uri[] · max: 4Optional
Responses
201Success
post
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"
}
201Success

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()
Response
{
  "images": [
    {
      "url": "https://cdn.aimlapi.com/squirrel/files/panda/qMuknweKekEYlj9-RdUNt_f0706e451d674554a4c03f2489cf7d5a.jpg",
      "content_type": "image/jpeg",
      "file_name": null,
      "file_size": null,
      "width": 1184,
      "height": 880
    }
  ],
  "timings": {},
  "seed": 3959063143,
  "has_nsfw_concepts": [
    false
  ],
  "prompt": "Add a bird to the foreground of the photo."
}
Reference Image
Generated Image
More generated images
"Add a crown to the T-rex's head."
"Add a couple of silver wings"
"Remove the dinosaur. Place a book and a bouquet of wildflowers in blue and pink tones on the lounge chair. Let a light foamy surf gently wash the bottom of the chair. Don't change anything else."
"Make the dinosaur sit on a lounge chair with its back to the camera, looking toward the water. The setting sun has almost disappeared below the horizon."

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.

Our input images
Our chilling T-rex
Our blue mug
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()
Response
{
  "images": [
    {
      "url": "https://cdn.aimlapi.com/squirrel/files/lion/rXRknU80d-8ywPnLBq4G8_59b65fe44d8046a38ab9e524a5a8b61c.jpg",
      "width": 1184,
      "height": 880,
      "content_type": "image/jpeg"
    }
  ],
  "timings": {},
  "seed": 1068148133,
  "has_nsfw_concepts": [
    false
  ],
  "prompt": "Place this image with the t-rex on this mug from the second image as a print. Make it look fit and natural."
}
"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?