MAI Image 2.7

This guide shows how to generate images using the MAI Image 2.7 model via the Leonardo.AI REST API.

Sample Request

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v2/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --header 'content-type: application/json' \
     --data '{
       "model": "microsoft/mai-image-2.7",
       "parameters": {
           "width": 1536,
           "height": 1024,
           "prompt": "A cozy reading nook by a rain-streaked window, warm lamp light, stacked books and a sleeping cat",
           "quantity": 2,
           "guidances": {
               "image_reference": [
                   {
                       "image": {
                           "id": "YOUR_UPLOADED_IMAGE_ID",
                           "type": "UPLOADED"
                       }
                   }
               ]
           }
       },
       "public": false
   }'

API Request Endpoint, Headers, Parameters

Endpoint

https://cloud.leonardo.ai/api/rest/v2/generations

Headers

--header "accept: application/json" \
--header "authorization: Bearer <YOUR_API_KEY>" \
--header "content-type: application/json"

Body Parameters

ParameterTypeDefinition
guidancesobjectOptional. Object defining image guidance inputs that influence the generated result.
guidances.image_referencearrayOptional. Array of up to 5 reference images. Each reference includes image.type (UPLOADED, GENERATED, VARIATION, URL, or BASE64) and the matching image.id, image.url, or image.data. Optionally set order (integer, minimum 0) to control the position of each reference in the list.
heightintegerOptional. Height input resolution. Supports 768 to 5456 in multiples of 16. Width × height must be at most 4,194,304 pixels. Defaults to 1024.
modelstringRequired. Model identifier. Set to microsoft/mai-image-2.7.
promptstringRequired. Text prompt describing what image you want the model to generate. Supports 1 to 9999 characters.
prompt_enhancestringOptional. Controls prompt enhancement. Supports AUTO, ON, or OFF. Defaults to AUTO.
publicbooleanOptional. Boolean flag that determines whether the generation is public (true) or private (false).
quantityintegerOptional. Number of images to generate in a single request. Supports 1 to 8. Defaults to 4.
transparencybooleanOptional. Whether the image can be generated with a transparent background. Defaults to false.
widthintegerOptional. Width input resolution. Supports 768 to 5456 in multiples of 16. Width × height must be at most 4,194,304 pixels. Defaults to 1024.

Did this page help you?