I've been integrating with Leonardo AI’s API, and I've successfully accomplished the following:
Uploading an image via the init-image endpoint.
Generating images using models such as Leonardo Phoenix or Leonardo Kino XL without any hitches.
However, I'm encountering an issue when attempting to generate an image using an initial image as guidance (ControlNet).
The Challenge: Missing Prompt Error
When making an API call for image generation with guidance, I'm following these procedures:
Uploading an image and obtaining the initImageId.
Including this initImageId in the JSON request body as specified in the official documentation.
Incorporating the necessary parameters such as modelId, presetStyle, photoReal, controlnets, and so forth.
Submitting the API request to https://cloud.leonardo.ai/api/rest/v1/generations .
However, the response indicates an error message stating that the required “prompt” is missing, despite its inclusion in the request body.
My Troubleshooting Steps
Reviewing the API documentation and structuring my request precisely as recommended.
Experimenting with various JSON formats, ensuring the prompt is consistently present.
Trying different models (e.g., Leonardo Phoenix, Leonardo Kino XL).
Testing different methods for passing initImageId, such as setting “initImageType” to “UPLOADED” or “GENERATED”.
Attempting to send the request via both Postman and callin.io – the issue persists.
My API Request JSON (Example)
json
{
"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
}
]
}
Error Response:
[400] expecting a value for non-nullable variable: “prompt”
Has anyone successfully utilized image guidance (ControlNet) with Leonardo AI through its API?
Is there a specific format or an additional parameter required when using an initImageId?
Could this be an issue with the platform, or am I overlooking a critical detail?
I'd appreciate any insights or solutions anyone might have found for this! Thank you in advance.
I've been testing a very similar use case with success.
The only difference I can spot is the comment at the end of your prompt line – try removing the //
and everything that follows on that line.
PS - We're planning to introduce native support for controlnets for image guidance in the Leonardo AI app shortly!
After further investigation, this appears to be the most probable cause. The JSON specification does not include support for comments.
Hey, thanks, David. It appears the issue was with the //.