# MAI Image API: size, editing and errors Source: https://ofox.io/docs/develop/models/mai-image Microsoft's image generation and editing models, three in total, called through the OpenAI-compatible API in much the same way as GPT Image: text to image uses `/v1/images/generations`, and editing uses `/v1/images/edits`. ## Choosing a model **Model IDs (copy them exactly)** - MAI Image 2.5 Pro: `microsoft/mai-image-2.5-pro` — Complex compositions; consistent people and objects - MAI Image 2.5: `microsoft/mai-image-2.5` — Precise local edits - MAI Image 2.5 Flash: `microsoft/mai-image-2.5-flash` — Low latency; batch generation All three take the same parameters; in our tests a 1024×1024 image takes about 12 to 25 seconds. For live prices, see the [model page](https://ofox.io/models/microsoft/mai-image-2.5). ## Text to image **Python** ```python filename="mai_image.py" import base64 from openai import OpenAI client = OpenAI(api_key="YOUR_OFOX_API_KEY", base_url="https://api.ofox.io/v1", timeout=600) resp = client.images.generate( model="microsoft/mai-image-2.5-flash", prompt="A red apple on a white table", size="1024x1024", ) with open("output.png", "wb") as f: f.write(base64.b64decode(resp.data[0].b64_json)) ``` **cURL** ```bash filename="Terminal" curl https://api.ofox.io/v1/images/generations \ --max-time 600 \ -H "Authorization: Bearer $OFOX_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "microsoft/mai-image-2.5-flash", "prompt": "A red apple on a white table", "size": "1024x1024" }' | jq -r '.data[0].b64_json' | base64 --decode > output.png ``` ## Size (`size`) **Key point**:`size` only sets the aspect ratio. Output is about 1 megapixel, and passing a larger size does not increase the resolution. | Requested `size` | Actual output | |---|---| | Omitted | 1024×1024 | | `1024x1024`, `2048x2048`, `4096x4096` | 1024×1024 | | `1536x1024` | 1248×832 | | `1024x1536` | 832×1248 | | `100x100` | 768×768 | - The output keeps the requested aspect ratio, with total pixels adjusted to about 1 million; a size that is too small produces 768×768. - For higher resolutions, use [Nano Banana Pro](https://ofox.io/docs/develop/models/nano-banana) (up to 4K) or [GPT Image](https://ofox.io/docs/develop/models/gpt-image). ## Image editing ```bash filename="Terminal" curl https://api.ofox.io/v1/images/edits \ --max-time 600 \ -H "Authorization: Bearer $OFOX_API_KEY" \ -F model=microsoft/mai-image-2.5 \ -F prompt="Make the apple purple, keep everything else the same" \ -F image=@apple.jpg \ | jq -r '.data[0].b64_json' | base64 --decode > apple_purple.png ``` Reference images count as input tokens; see `usage.input_tokens_details.image_tokens` in the response. We measured 576 tokens for one 768×768 reference image. ## Common errors | Error | Cause | Fix | |---|---|---| | Request timeout | The client timeout is too short | Set the timeout to 300 seconds or more | | `404 model_not_found` | Model ID misspelled | Copy the model ID from this page | For multiple images, send several requests concurrently, one image per request. ## FAQ **Can MAI Image generate 2K or 4K images?** No. size only sets the aspect ratio, and the output is about 1 megapixel in total. In our tests both 2048x2048 and 4096x4096 produced 1024x1024. For higher resolutions, use Nano Banana Pro or GPT Image. **How do I edit images with MAI Image?** Use /v1/images/edits and upload the image file as a multipart form, the same way as with GPT Image.