Issue with Leonardo AI API Call – Image Generation with Guidance (ControlNet) 🚀

I’ve been working with Leonardo AI’s API, and I’ve successfully managed to:

:white_check_mark: Upload an image using the init-image endpoint.

:white_check_mark: Create images using models like Leonardo Phoenix or Leonardo Kino XL without any issues.

However, when I try to generate an image using an initial image as guidance (ControlNet) , I run into an issue.

:small_blue_diamond: The problem: Missing Prompt Error

When making an API call to generate an image with guidance, I follow these steps:

:one: I upload an image and retrieve the initImageId. :white_check_mark:

:two: I pass this initImageId into the JSON request body as per the official documentation. :white_check_mark:

:three: I include the required parameters such as modelId, presetStyle, photoReal, controlnets, etc. :white_check_mark:

:four: I send the API request to https://cloud.leonardo.ai/api/rest/v1/generations. :x:

However, the response returns an error stating that the expected “prompt” is missing, even though I’ve included it in the request body.

:small_blue_diamond: What I’ve Tried

:arrows_counterclockwise: Checked the API documentation and formatted my request exactly as suggested.

:arrows_counterclockwise: Tested different JSON structures, ensuring that prompt is always included.

:arrows_counterclockwise: Tried different models (e.g., Leonardo Phoenix, Leonardo Kino XL ).

:arrows_counterclockwise: Experimented with different ways to pass initImageId, such as “initImageType”: “UPLOADED” or “initImageType”: “GENERATED”.

:arrows_counterclockwise: Tried sending the request in both Postman and Make.com – still the same issue.

:small_blue_diamond: My API Request JSON (Example)

{
“height”: 512,
“modelId”: “aa77f04e-3eec-4034-9c07-d0f619684628”,//Leonardo Kino XL
“prompt”: “A wistful young woman stands in the beaming doorway of a sunlit room”,
“presetStyle”:“CINEMATIC”,
“width”: 1024,
“photoReal”: true,
“photoRealVersion”:“v2”,
“alchemy”:true,
“controlnets”: [
{
“initImageId”: “{{70.id}}”,
“initImageType”: “UPLOADED”,
“preprocessorId”: 67,
“strengthType”: “High”,
“influence”: 0.64
}
]
}

:boom: Error Response:

[400] expecting a value for non-nullable variable: “prompt”

:bulb: Has anyone successfully used image guidance (ControlNet) in Leonardo AI via API?

:bulb: Is there a specific format or additional parameter required when using an initImageId?

:bulb: Could this be a bug, or am I missing something crucial?

Would love to hear if anyone has found a fix for this! Thanks in advance. :pray::fire:

1 Like

I have a very similar usage that I’ve been testing successfully.

The only difference I can see is the comment at the end of your prompt line - try removing the // and everything after on that line.

PS - We’re aiming to have native support for controlnets for image guidance in the Leonardo AI app soon!

1 Like

On further checking that looks extremely likely to be the problem - the JSON spec doesn’t provide for comments.

See: Can comments be used in JSON? - Stack Overflow

1 Like

Hey, thanks, David. It seems that the issue was the //.

2 Likes