โš ๏ธ 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/generations endpoint. The library handles this automatically โ€” just provide your .services.ai.azure.com base 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:

FeatureMAI-Image-2FLUX.2
API styleSynchronous (direct response)Asynchronous (202 + polling)
API path/mai/v1/images/generationsBFL provider path
Prompt limit32,000 characters~1,000 characters
Min dimensions768px (per side)256px
Max dimensions1M total pixelsModel-dependent
InterfaceIImageGeneratorIImageGenerator
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 three
var 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

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


One response to “๐Ÿ–ผ๏ธ MAI-Image-2 Just Dropped โ€” And .NET Support Is Already Here”

  1. […] MAI-Image-2 Just Dropped — And .NET Support Is Already Here (Bruno Capuano) […]

    Like

Leave a reply to Dew Drop – April 14, 2026 (#4646) – Morning Dew by Alvin Ashcraft Cancel reply

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading