---
name: generate-images-mai
description: 'Generate or edit bitmap images with Microsoft MAI-Image-2.5 through the Azure AI image APIs. Use for text-to-image generation, image-to-image edits, object removal or replacement, inpainting, text updates, artifact cleanup, reference-image transformations, posters, thumbnails, and concept art.'
argument-hint: 'Describe the image or edit and optionally provide an input image, output path, width, and height'
user-invocable: true
disable-model-invocation: false
title: generate-images-mai
canonical_url: https://skilld.dev/gh/pamelafox/presentation-skills/generate-images-mai
last_updated: 2026-11-12T08:19:45.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/generate_image.py](https://skilld.dev/api/skills-raw/pamelafox/presentation-skills/generate-images-mai/scripts/generate_image.py), [scripts/test_generate_image.py](https://skilld.dev/api/skills-raw/pamelafox/presentation-skills/generate-images-mai/scripts/test_generate_image.py).
>
> If the user asked to install this Skill, run `npx skilld install pamelafox/presentation-skills/generate-images-mai`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/generate-images-mai`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/pamelafox/presentation-skills/generate-images-mai) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/generate-images-mai`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/generate-images-mai --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/generate-images-mai --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Generate and edit images with MAI-Image-2.5

Create an image from text or edit a supplied JPEG or PNG, save the result, and verify that the output is usable.

## Requirements

- Python 3.10+.
- A `.env` file in the current directory or one of its parents:

```dotenv
AZURE_API_KEY=your-key
AZURE_IMAGE_ENDPOINT=https://your-resource.services.ai.azure.com/mai/v1/images/generations
```

The endpoint can be the resource root, `/mai/v1/images`, `/generations`, or `/edits`; the script selects the operation-specific path.

Never read, print, return, commit, or embed the API key in generated files, commands, logs, or chat. Do not create a `.env` containing a real secret. If configuration is missing, tell the user which variable to add without asking them to send its value through chat.

## Procedure

1. Determine the requested subject or edit, intended use, output path, dimensions, and visual constraints from the conversation.
2. For an edit, confirm that the input is a readable JPEG or PNG. Preserve the original composition or identity unless the request says otherwise.
3. If the prompt is underspecified, preserve the user's intent and add only useful visual detail: medium, composition, environment, lighting, palette, camera or rendering style, and important exclusions. Do not introduce brands, people, text, or sensitive attributes the user did not request.
4. Default to `1024x1024` and `generated_image.png` for generation. Generation dimensions must each be at least 768 pixels and contain no more than 1,048,576 total pixels. Edit output is always PNG and dimensions are controlled by the service.
5. Run [generate_image.py](https://skilld.dev/api/skills-raw/pamelafox/presentation-skills/generate-images-mai/scripts/generate_image.py) with the refined prompt. Pass arguments as separate shell tokens and quote all user-provided values.

Text-to-image generation:

```bash
python3 scripts/generate_image.py \
  --prompt "A photograph of a red fox in an autumn forest" \
  --width 1024 \
  --height 1024 \
  --output generated_image.png
```

Image-to-image edit:

```bash
python3 scripts/generate_image.py \
  --prompt "Replace the lawn with a native wildflower garden while preserving the house and paths" \
  --input-image garden.png \
  --output edited_garden.png
```

6. If the destination exists, do not overwrite it unless the user explicitly requested replacement; use a new descriptive filename or pass `--force` only with that permission.
7. Verify the output exists, is non-empty, and can be decoded as an image. Use the image-viewing tool to inspect it when available.
8. Check that the result matches the requested subject or edit, composition, legibility, and safety constraints. Regenerate with a targeted prompt adjustment when the image is blank, malformed, materially off-topic, or has obvious layout defects.
9. Report the saved path and, when available, final dimensions. Mention prompt changes only when they materially affect the user's request.

## Options

- `--prompt`: Required image description or editing instruction.
- `--input-image`: Optional JPEG or PNG image to edit. When present, the script uses the MAI image edits API.
- `--output`: Output PNG path; defaults to `generated_image.png`.
- `--width` and `--height`: Generation dimensions; each defaults to `1024`. Ignored for edits.
- `--model`: Deployment name; defaults to `MAI-Image-2.5`.
- `--endpoint`: Azure resource or image API endpoint; overrides `AZURE_IMAGE_ENDPOINT`.
- `--env-file`: Loads a specific `.env` file instead of searching parent directories.
- `--force`: Permits replacing an existing output file.

Environment variables already present in the process take precedence over values in `.env`.

## API behavior

- Text generation sends JSON to `/mai/v1/images/generations`.
- Image editing sends `prompt`, `model`, and one `image` as multipart form data to `/mai/v1/images/edits`.
- Image edits accept JPEG or PNG input and return PNG output.
- MAI-Image-2.5 image editing is currently a public-preview feature and isn't recommended for production workloads without accounting for preview limitations.

## Failure handling

- Missing configuration: Identify `AZURE_API_KEY` or `AZURE_IMAGE_ENDPOINT` and stop.
- Invalid input image: Report that image edits require a readable JPEG or PNG.
- HTTP authentication failure: Tell the user to verify `AZURE_API_KEY` locally; never request the key in chat.
- HTTP endpoint or deployment failure: Report the status and sanitized API message, then verify the endpoint and deployment name.
- Invalid or absent `b64_json`: Do not create an output file; report the response-shape problem.
- Content-policy rejection: Explain that the service rejected the prompt and offer a compliant revision.
- Corrupt or empty image: Remove the incomplete output and retry once with the same request before changing the prompt.

## Completion checks

- The secret was not exposed.
- The requested output was created without overwriting unrelated work.
- The file is a decodable image.
- Visual inspection confirms the primary subject and requested edits are present.
- The user receives a clickable path to the image.

## Reference

- [Deploy and use MAI image models in Microsoft Foundry](https://learn.microsoft.com/azure/foundry/foundry-models/how-to/use-foundry-models-mai-image)
