Generate Images Using Leonardo FLUX.1 Kontext [pro]

Generate Image from Text Prompts

The guide will recreate the following functionality in the Web UI via API.

Sample Request

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v1/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --header 'content-type: application/json' \
     --data '
{
    "prompt": "a portrait-style photograph featuring a koala sitting against a neutral beige background. The koala has soft, fluffy gray fur with a lighter patch on its chest and around its nose. Its ears are large and fluffy, adding to its endearing look. The lighting is soft, highlighting the texture of the fur. The overall composition is centered, with the koala directly facing the camera, creating a charming and engaging image.",
    "modelId": "28aeddf8-bd19-4803-80fc-79602d1a9989",
    "styleUUID": "111dc692-d470-4eec-b791-3475abac4c46",
    "num_images": 1,
    "width": 832,
    "height": 1248
}

πŸ“˜

Number Of Images

FLUX.1 Kontext [pro] can only generate 1 image at a time, make sure to have "num_images":1 specified

Sample Output

FLUX.1 Kontext [pro] with the prompt "a portrait-style photograph featuring a koala sitting against a neutral beige background. The koala has soft, fluffy gray fur with a lighter patch on its chest and around its nose. Its ears are large and fluffy, adding to its endearing look. The lighting is soft, highlighting the texture of the fur. The overall composition is centered, with the koala directly facing the camera, creating a charming and engaging image

FLUX.1 Kontext [pro] with the prompt "a portrait-style photograph featuring a koala sitting against a neutral beige background. The koala has soft, fluffy gray fur with a lighter patch on its chest and around its nose. Its ears are large and fluffy, adding to its endearing look. The lighting is soft, highlighting the texture of the fur. The overall composition is centered, with the koala directly facing the camera, creating a charming and engaging image"


Generate from Image Reference with Generated Image

Sample Request

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v1/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --header 'content-type: application/json' \
     --data '
{
    "prompt": "This koala is wearing a white sunglasses",
    "modelId": "28aeddf8-bd19-4803-80fc-79602d1a9989",
    "styleUUID": "111dc692-d470-4eec-b791-3475abac4c46",
    "num_images": 1,
    "width": 832,
    "height": 1248,
    "contextImages": [{
        "type": "GENERATED",
        "id": "0e53510d-e321-411f-b0dc-9cdb63ca1732"
    }]
}

Input Image

Sample Output

FLUX.1 Kontext [pro] with the prompt "This koala is wearing a white sunglasses

FLUX.1 Kontext [pro] with the prompt "This koala is wearing a white sunglasses"


Generate from Image Reference with Uploaded Image

Sample Request

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v1/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --header 'content-type: application/json' \
     --data '
{
    "prompt": "a kangaroo wearing a scarf",
    "modelId": "28aeddf8-bd19-4803-80fc-79602d1a9989",
    "styleUUID": "111dc692-d470-4eec-b791-3475abac4c46",
    "num_images": 1,
    "width": 832,
    "height": 1248,
    "contextImages": [{
        "type": "UPLOADED",
        "id": "0edab5a7-2efe-49b4-9283-7c79dd642981"
    }]
}

Input Uploaded Image

Sample Output

FLUX.1 Kontext [pro] with the prompt "a kangaroo wearing a scarf"

FLUX.1 Kontext [pro] with the prompt "a kangaroo wearing a scarf"


Required Parameters

  • modelId

    ModelModel ID
    FLUX.1 Kontext [pro]28aeddf8-bd19-4803-80fc-79602d1a9989
  • prompt - Text prompt to use for generation.

Supported Parameters

  • enhancePrompt (Prompt Enhance)

    • For OFF, set to false.
    • For ON, set to true and do not specify enhancePromptInstruction.
    • For Edit with AI, set to true and specify enhancePromptInstruction: "INSTRUCTION_AS_STRING".
  • height - Height input resolution. FLUX.1 Kontext [pro] only accept 672, 720, 752, 832, 880, 944, 1024, 1104, 1184, 1248, 1392, 1456, 1568.

  • num_images - Number of images, FLUX.1 Kontext [pro] only allow you to generate 1 image at a time.

  • styleUUID (Preset Style)

    Preset StyleUUID
    3D Renderdebdf72a-91a4-467b-bf61-cc02bdeb69c6
    Acrylic3cbb655a-7ca4-463f-b697-8a03ad67327c
    Creative6fedbf1f-4a17-45ec-84fb-92fe524a29ef
    Dynamic111dc692-d470-4eec-b791-3475abac4c46
    Fashion594c4a08-a522-4e0e-b7ff-e4dac4b6b622
    Game Concept09d2b5b5-d7c5-4c02-905d-9f84051640f4
    Graphic Design 2D703d6fe5-7f1c-4a9e-8da0-5331f214d5cf
    Graphic Design 3D7d7c2bc5-4b12-4ac3-81a9-630057e9e89f
    Illustration645e4195-f63d-4715-a3f2-3fb1e6eb8c70
    None556c1ee5-ec38-42e8-955a-1e82dad0ffa1
    Portrait8e2bc543-6ee2-45f9-bcd9-594b6ce84dcd
    Portrait Cinematic4edb03c9-8a26-4041-9d01-f85b5d4abd71
    Portrait Fashion0d34f8e1-46d4-428f-8ddd-4b11811fa7c9
    Pro B&W photography22a9a7d2-2166-4d86-80ff-22e2643adbcf
    Pro Color Photography7c3f932b-a572-47cb-9b9b-f20211e63b5b
    Pro Film Photography581ba6d6-5aac-4492-bebe-54c424a0d46e
    Ray Tracedb504f83c-3326-4947-82e1-7fe9e839ec0f
    Stock Photo5bdc3f2a-1be6-4d1c-8e77-992a30824a2c
    Watercolor1db308ce-c7ad-4d10-96fd-592fa6b75cc4

  • width - Width input resolution. FLUX.1 Kontext [pro] only accept 672, 720, 752, 832, 880, 944, 1024, 1104, 1184, 1248, 1392, 1456, 1568.
  • type - Source of the image, GENERATED or UPLOADED
  • id - The image UUID returned by the upload or by generation.

πŸ“˜

Note

If using the seedparameter, the maximum seed number is 2147483638.

Cost

The FLUX.1 Kontext [pro] costs 50 API Credits per image.