API Error Messages

Debug common issues encountered when integrating to Leonardo.Ai via API

If you experience issues integrating your application via API, this list helps you troubleshoot. If you continue to have trouble, contact Leonardo.Ai support for further assistance.

Invalid response from authorization hook

{  
  "error": "Invalid response from authorization hook",  
  "path": "$",  
  "code": "unexpected"  
}

Check if your API key follows a valid UUID format.

Check if your API key is correct.

Check if you are setting the API key correctly. It should be added to the request header as authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.

For example, when using the curl command:

curl --request POST \

     --url https://cloud.leonardo.ai/api/rest/v1/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' \
     --header 'content-type: application/json' \
     --data '
{
  "height": 512,
  "modelId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
  "prompt": "An oil painting of a cat",
  "width": 512
}
'

Authentication hook unauthorized this request

{
  "error": "Authentication hook unauthorized this request",
  "path": "$",
  "code": "access-denied"
}

Similar to Invalid response from authorization hook, check if you are setting the API key correctly. It should be added to the request header as authorization: Bearer XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.

Invalid file extension

{  
  "error": "invalid file extension",  
  "path": "$",  
  "code": "unexpected"  
}

The extension parameter in Upload Init Image API is the file extension of the image you will upload. Examples of file extensions are png, jpg, jpeg, and webp . The extension parameter does not accept filenames or the image data.

The Upload Init Image API returns a presigned URL for uploading the image. Detailed instructions for using the returned presigned URL are available in the guide: How to upload an image using a presigned URL.

Expected a boolean for type Boolean but found a string

{  
  "error": "expected a boolean for type 'Boolean', but found a string",  
  "path": "$.selectionSet.sdGenerationJob.args.arg1.photoReal",  
  "code": "validation-failed"  
}

Check if your code is converting your input into string instead of a Boolean value. The accepted values are true or false. Setting "true" or "false" in quotations may be interpreted as string.

Photoreal mode, unexpected model id provided

{  
  "error": "photoreal mode, unexpected model id provided",  
  "path": "$",  
  "code": "unexpected"  
}

When photoReal is set to true, you do not need to specify a model. Remove the modelId parameter when using photoReal.

Unexpected variable

{  
  "error": "Unexpected variable sd_Version",  
  "path": "$",  
  "code": "bad-request"  
}

Check if you are specifying the correct body parameter. Body parameters are case-sensitive. For example, sd_version is the correct parameter so specifying sd_Version will throw the unexpected variable error.

204 (No Content) when uploading an image

When uploading an image via a presigned URL, 204 is the expected success response code and there will be no content returned. The image ID will not be returned here. Instead, the image ID has already been returned in the previous step of calling the Upload Init Image API.

For example, the image ID is under uploadInitImage.id below:

{  
  "uploadInitImage": {  
    "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",  
    "fields": …,  
    "key": …,  
    "url": …  
  }  
}

403 Forbidden error when uploading an image

When uploading an image via a presigned URL, remove authentication-related headers like your API key because it is not necessary when using the presigned URL.

Couldn't access image

{  
  "error": "couldn't access image",  
  "path": "$",  
  "code": "unexpected"  
}

When using variations like the Create Upscale API and Create Unzoom API, the expected image ID is the ID of an image generated on Leonardo.Ai. This image ID is returned by the Get a Single Generation API.

For example, the image ID is under generations_by_pk.generated_images[0].id below:

{  
  "generations_by_pk": {  
    "generated_images": \[  
      {  
        "url": …,  
        "nsfw": …,  
        "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",  
        "likeCount": …,  
        "generated_image_variation_generics": \[]  
      },  
    ],  
   …  
  }  
}

Currently, we don’t support using variations on images uploaded via the Upload Init Image API.

Failed to find init variation

{  
  "error": "failed to find init variation",  
  "path": "$",  
  "code": "unexpected"  
}

Similar to Couldn't access image, the expected image ID is the ID of an image generated on Leonardo.Ai. This image ID is returned by the Get a Single Generation API.

Invalid init image id

{  
  "error": "invalid init image id",  
  "path": "$",  
  "code": "unexpected"  
}

Check if your init image ID follows a valid UUID format.

Theinit_image_idparameter accepts the image ID returned by the Upload Init Image API. To use an image generated in Leonardo.Ai as init image, specify the image ID in the init_generation_image_id parameter instead.

200 Success but image URL array is empty

Check if the response body contains "status": "COMPLETE". The endpoint returns an attribute generations_by_pk.status. Successfully completed image generation would have a status of COMPLETE.

The reason is that Get a Single Generation API endpoint is returning 200 success response with an empty generations_by_pk.generated_images[]. Image URLs are not returned.

Image generation is not instantaneous so be sure you are not getting the images immediately after sending a generate images request. The best practice is to specify a webhook callback when creating the API key to receive a message containing the URL of generated images.

Key Creation Error Occurred

Symptom: Generating a Production API key while specifying a webhook callback results to a UI error saying "Key Creation Error Occurred".

Check if you are using https for the webhook URL and not http. You can find the following console error "WebhookCallbackUrl is not a valid url" if you use http:

{  
    "errors": [  
        {  
            "message": "WebhookCallbackUrl is not a valid url (must be https://)",  
            "extensions": {  
                "path": "$",  
                "code": "unexpected"  
            }  
        }  
    ]  
}

Failed to find init variation

{  
  "error": "failed to find init variation",  
  "path": "$",  
  "code": "unexpected"  
}

When using variation API endpoints like unzoom and no background, setting the parameter isVariation to true means that the image ID you are supplying is a product of a previous variation.

For example, you used the variation API endpoint upscale and got an image ID. If you wish to use no background on that ID, you need to set isVariation to true.

If the ID is not from a previous variation, set isVariation to false or don't specify it.

Not enough API tokens

{
  "error": "not enough api tokens userId: XXXXXXXXX-XXXXX-XXXXX-XXXXXXXXXXXXXXXXXX",
  "path": "$",
  "code": "unexpected"
}

All API credits have been used up from your account and will need to be topped up.

Service Error

{
"error": "Service Error",
"path": "$",
"code": "unexpected"
}

This is a generic error message from Leonardo.Ai. Reach out to support for further troubleshooting.