Microsoft’s MAI-Image-2.7 and MAI-Image-2.7-Flash are now available in public preview on AI Gateway. Both increase the maximum output size to 2048 x 2048 pixels and add transparent backgrounds for generated and edited images.
Generate images from text or edit existing images with one AI Gateway API key, without a Microsoft account. Both models support photorealistic images, text rendering, and targeted edits to products, portraits, and layouts. Use up to five reference images to guide edits or combine subjects.
MAI-Image-2.7 (
microsoft/mai-image-2.7): for final assets where image quality is the priorityMAI-Image-2.7-Flash (
microsoft/mai-image-2.7-flash): for faster, lower-cost generation when exploring prompts or creating variations
Set the AI_GATEWAY_API_KEY environment variable, then use either model ID with AI SDK 6 or later. To generate a transparent PNG, set providerOptions.azure.background to 'transparent':
import { generateImage } from 'ai';import { writeFileSync } from 'node:fs';
const { image } = await generateImage({ model: 'microsoft/mai-image-2.7', prompt: 'A glass perfume bottle, studio product shot', size: '2048x2048', providerOptions: { azure: { background: 'transparent' }, },});
writeFileSync('bottle.png', image.uint8Array);To edit an image, provide it as a reference and describe what to change:
import { generateImage } from 'ai';import { readFileSync, writeFileSync } from 'node:fs';
const { image } = await generateImage({ model: 'microsoft/mai-image-2.7-flash', prompt: { text: 'Place the bottle on a marble counter', images: [readFileSync('bottle.png')], },});
writeFileSync('counter.png', image.uint8Array);You can also generate and edit images from the terminal with the AI CLI, using the same API key and model IDs:
npm install -g ai-cliai image -m microsoft/mai-image-2.7 --size 2048x2048 -o bottle.png "A glass perfume bottle, studio product shot"ai image -m microsoft/mai-image-2.7-flash -i bottle.png -o counter.png "Place the bottle on a marble counter"Try MAI-Image-2.7 or MAI-Image-2.7-Flash in the model playground, or follow the image generation guide.