โ ๏ธ This blog post was created with the help of AI tools. Yes, I used a bit of magic from language models to organize my thoughts and automate the boring parts, but the geeky fun and the ๐ค in C# are 100% mine.
Hi!
When Microsoft announced MAI-Image-2, I immediately thought: “I need to add this to ElBruno.Text2Image. Today.”
So I did. ๐
MAI-Image-2ย is Microsoft’s new image generation model on Microsoft Foundry โ high-quality generation, aย synchronous APIย (no polling!), a 32K character prompt limit, and flexible dimensions. And it’s already supported inย ElBruno.Text2Imageย with the same clean interface you already know.
Let me show you how it works.
โ๏ธ Getting Started โ MAI-Image-2 on Azure AI Foundry
MAI-Image-2 delivers high-quality image generation with a simpler developer experience than FLUX.2. The API is synchronous โ you send a request, you get an image back. No 202 status codes, no polling loops, no waiting callbacks. Just a prompt and a picture.
Here’s all you need:
using ElBruno.Text2Image;using ElBruno.Text2Image.Foundry;using var generator = new MaiImage2Generator( endpoint: "https://your-resource.services.ai.azure.com", apiKey: "your-api-key", modelId: "MAI-Image-2");var result = await generator.GenerateAsync( "a futuristic cityscape with neon lights, cyberpunk style");await result.SaveAsync("mai-image2-output.png");Console.WriteLine($"Generated in {result.InferenceTimeMs}ms");
Setting up credentials
The library reads from User Secrets, environment variables, or appsettings.json. For local development:
dotnet user-secrets set MAI_IMAGE2_ENDPOINT "https://your-resource.services.ai.azure.com"dotnet user-secrets set MAI_IMAGE2_API_KEY "your-api-key-here"dotnet user-secrets set MAI_IMAGE2_MODEL_ID "MAI-Image-2"
๐ก Fun fact: MAI-Image-2 uses a dedicated
/mai/v1/images/generationsendpoint. The library handles this automatically โ just provide your.services.ai.azure.combase URL and it builds the correct API path for you.
โก Key Differences from FLUX.2
If you’re already using FLUX.2 with this library, here’s how MAI-Image-2 compares:
| Feature | MAI-Image-2 | FLUX.2 |
|---|---|---|
| API style | Synchronous (direct response) | Asynchronous (202 + polling) |
| API path | /mai/v1/images/generations | BFL provider path |
| Prompt limit | 32,000 characters | ~1,000 characters |
| Min dimensions | 768px (per side) | 256px |
| Max dimensions | 1M total pixels | Model-dependent |
| Interface | IImageGenerator | IImageGenerator |
| DI support | โ Same pattern | โ Same pattern |
| Endpoint auto-conversion | โ | โ |
The synchronous API is a big deal for developer experience. No more writing polling loops or handling intermediate states. Send a prompt, get an image. Done.
๐ Same Interface, Multiple Backends
๐งฉ Microsoft.Extensions.AI Compatible
Every generator in the library โ including the new MaiImage2Generator โ implements the standard Microsoft.Extensions.AI.IImageGenerator interface from the
Microsoft.Extensions.AI.Abstractions package. This means you can use ElBruno.Text2Image as a drop-in provider anywhere the MEAI abstraction is expected โ dependency
injection, middleware pipelines, or any framework that programs against IImageGenerator. Cloud or local, FLUX.2 or MAI-Image-2 or Stable Diffusion โ they all plug
into the same standard .NET AI contract.
// MAI-Image-2 (cloud)IImageGenerator generator = new MaiImage2Generator(endpoint, apiKey, modelId: "MAI-Image-2");// FLUX.2 Pro (cloud)IImageGenerator generator = new Flux2Generator(endpoint, apiKey, modelId: "FLUX.2-pro");// Stable Diffusion 1.5 (local)IImageGenerator generator = new StableDiffusion15();// Same API for all threevar result = await generator.GenerateAsync("a beautiful landscape");
๐ Dependency Injection
If you’re building with DI, the library has an extension method ready to go:
services.AddMaiImage2Generator( endpoint: "https://your-resource.services.ai.azure.com", apiKey: "your-api-key", modelId: "MAI-Image-2");
Same pattern as the FLUX.2 registration. Inject IImageGenerator and you’re done.
๐ Links
- Repository:ย github.com/elbruno/ElBruno.Text2Image
- NuGet:ย nuget.org/packages/ElBruno.Text2Image.Foundry
- MAI-Image-2 Announcement:ย Introducing MAI-Image-2
- Setup Guide:ย MAI-Image-2 Setup Guide
- v0.8.0 Release:ย github.com/elbruno/ElBruno.Text2Image/releases/tag/v0.8.0
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno

Leave a comment