Items marked preview in this article are currently in preview. This preview is provided without a service-level agreement, and Microsoft doesn’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
- Deploy MAI image models in Microsoft Foundry
- Authenticate by using Microsoft Entra ID or API keys
- Generate images by using the MAI image generations API
- Run an image edit by using the MAI image edits API
Prerequisites
- An Azure subscription with a valid payment method. If you don’t have an Azure subscription, create a paid Azure account.
- Access to Microsoft Foundry with appropriate permissions to create and manage resources.
- A Microsoft Foundry project in a region supported for the MAI image model you want to deploy. For each model’s supported deployment regions, see Region availability for Foundry Models sold by Azure.
- Cognitive Services Contributor role on the Azure AI Foundry resource to deploy models. For more information, see Azure RBAC roles.
MAI image models at a glance
MAI image models in Microsoft Foundry include:
For each model’s supported deployment regions, see Region availability for Foundry Models sold by Azure.
To learn more about the individual models, see MAI image model capabilities.
Deploy MAI image models
To deploy an MAI image model, follow the instructions in Deploy Microsoft Foundry Models in the Foundry portal. Alternatively, you can deploy the model by using the Azure CLI. The following code shows deployment ofMAI-Image-2.5. To deploy a different model, replace the model name and version in the lines --model-name MAI-Image-2.5 and --model-version 2026-06-02 with the values for your desired model.
Replace <ACCOUNT_NAME>, <RESOURCE_GROUP>, <DEPLOYMENT_NAME> with your values.
Run text-to-image generation
MAI image models can generate high-quality images from natural language prompts, enabling users to translate textual descriptions into visually coherent outputs suitable for a wide range of creative and design use cases. The following example shows how to generate an image from a text prompt using an MAI image model with the MAI image generations API.- Python
- REST API
Use API key authentication
-
Install the
requestslibrary: -
Set environment variables:
-
Run the following code:
Expected output: A JSON response containing the generated image data in base64 format. The response includes the image data, which you decode and save as
output.pngin the current directory. For more information, see Response format.
Use Microsoft Entra ID authentication
To use Microsoft Entra ID instead of an API key, replace theapi-key header with a bearer token obtained using the DefaultAzureCredential:-
Install the Azure Identity library:
-
Update the request headers in the API key authentication code:
Reference: DefaultAzureCredential
Run an image-to-image edit
Some MAI image models support precise, controllable edits to existing images, including object removal, replacement, attribute changes, inpainting, text updates, and artifact cleanup while preserving composition and layout. For the list of models that support image-to-image edits, see MAI image models at a glance. The following example shows how to perform an image-to-image edit by using an MAI image model with the MAI image edits API.Requests for image-to-image edits use multipart form data and accept up to five reference images. Repeat the
image field for each file.- Python
- REST API
Use API key authentication
-
Install the
requestslibrary: -
Set environment variables:
-
Run the following code:
Expected output: A JSON response containing the edited image data in base64 format. The response includes the image data, which you decode and save as
output.pngin the current directory. For more information, see Response format.
MAI image model capabilities
MAI image models are diffusion-based generative models designed for both high-quality text-to-image generation and precise, controllable image-to-image editing. Each model uses a diffusion-based approach to progressively refine images from a natural language prompt, enabling strong alignment between the input text and the generated output.Core capabilities
All MAI image models in this article share these core capabilities:- Text-to-image generation: Generates high-quality images from natural language prompts, enabling users to translate textual descriptions into visually coherent outputs suitable for a wide range of creative and design use cases.
- Image-to-image editing: Supports precise, controllable edits to existing images, including object removal, replacement, attribute changes, inpainting, text updates, and artifact cleanup while preserving composition and layout.
- Photorealistic image synthesis: Generates realistic imagery with consistent visual structure, making it suitable for concept visualization and content creation scenarios.
- High-fidelity portraits: Generates expressive, natural-looking portraits with accurate facial structure, lighting, and texture.
- Product, branding, and commercial design: Well suited for product imagery, marketing visuals, brand assets, and commercial creative workflows.
- Accurate text rendering: Improved rendering of text within generated images, including labels, posters, packaging, and signage.
- Visual reasoning: Reasons across objects, scene structure, lighting, scale, and spatial positioning to produce consistent outputs, even from ambiguous prompts.
For more details, see the individual model cards in the Foundry model catalog and the capabilities comparison table in Foundry Models sold by Azure.
API endpoints
After you deploy an MAI image model, use the MAI image generations API to generate images and the MAI image edits API for image-to-image edits.-
Image generations API endpoint: A Microsoft-managed endpoint that accepts a text prompt and returns a PNG image. The API endpoint has the following form:
-
Image edits API endpoint: A Microsoft-managed endpoint that accepts up to five JPEG or PNG reference images and returns a PNG image. The API endpoint has the following form:
Request parameters
The following table lists the request parameters for the image APIs:Response format
Both the MAI image generations and image edits APIs return a JSON object that contains the generated PNG image as base64-encoded data. Decode theb64_json value to save the image as a PNG file.
The output format is always PNG. The maximum total pixel count is 2,359,296 (equivalent to 1536×1536) for
MAI-Image-2.6 and MAI-Image-2.6-Flash, and 1,048,576 (equivalent to 1024×1024) for MAI-Image-2.5 models. Both width and height must be at least 768 pixels each. Either dimension can exceed the equivalent square dimensions as long as the total pixel count stays within the applicable limit.
The following example shows a successful response:
API quotas and limits
MAI image models have the following rate limits measured in Requests Per Minute (RPM). The tier available to you depends on your subscription and deployment configuration.
To request a quota increase, submit the quota increase request form. Requests are processed in the order they’re received, and priority goes to customers who actively use their existing quota allocation.
Troubleshoot
Use the following table to resolve common errors when working with MAI image models:Responsible AI considerations
When using MAI image models in Foundry, consider these responsible AI practices:- Be aware of known limitations: Despite technical mitigations such as data filtering and content classifiers applied at the system level, image generation models can produce harmful or unexpected content based on user requests. Common risk areas include violent or gory content, sexual content or nudity, depictions of public figures, and replication of trademarked or other protected material.
- Configure content safety: Apply additional mitigations appropriate to your use case, because no generative model is immune to adversarial prompts.
- Comply with applicable terms: Ensure your use of generated images complies with Microsoft’s terms of service and applicable copyright and intellectual property laws.
- Be transparent: Disclose that content is AI-generated when sharing or publishing images.
- Avoid harmful content: Don’t generate content that could be harmful, misleading, or in violation of privacy.