> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/19.latest/using-the-api/image-generation/generating-images.md).

# Generating Images

Generate images from a text prompt and validate model constraints up front.

{% hint style="warning" %}
Image Generation is experimental and disabled by default. See [Enabling image generation](/ai-in-umbraco/19.latest/using-the-api/image-generation.md#enabling-image-generation).
{% endhint %}

Use `GenerateImagesAsync` to produce images from a text prompt (Tier 1).

## Basic usage

{% code title="HeroBanner.cs" %}

```csharp
#pragma warning disable UMBRACOAI_IMAGEGEN

using Microsoft.Extensions.AI;
using Umbraco.AI.Core.ImageGeneration;

public class HeroBanner
{
    private readonly IAIImageGenerationService _imageGenerationService;

    public HeroBanner(IAIImageGenerationService imageGenerationService)
    {
        _imageGenerationService = imageGenerationService;
    }

    public async Task<IList<AIContent>> Generate()
    {
        var response = await _imageGenerationService.GenerateImagesAsync(
            img => img.WithAlias("hero-banner"),
            "A serene mountain landscape at dawn");

        return response.Contents;
    }
}
```

{% endcode %}

Each item in `response.Contents` is a `DataContent` (inline bytes) or `UriContent` (hosted URL), depending on the model and requested response format.

## Choosing a profile and options

{% code title="Builder example" %}

```csharp
#pragma warning disable MEAI001 // ImageGenerationOptions is experimental in M.E.AI
#pragma warning disable UMBRACOAI_IMAGEGEN

using System.Drawing;
using Microsoft.Extensions.AI;

var response = await _imageGenerationService.GenerateImagesAsync(
    img => img
        .WithAlias("product-shot")
        .WithProfile("marketing-images")
        .WithImageGenerationOptions(new ImageGenerationOptions
        {
            Count = 2,
            ImageSize = new Size(1024, 1024),
        }),
    "A product photo of a ceramic coffee mug on a wooden table",
    cancellationToken);
```

{% endcode %}

Profile-level defaults (size and output media type) come from `AIImageGenerationProfileSettings`. Options passed to the builder override them per call. Quality and style are not core settings. The OpenAI provider adds them to the profile as provider-specific settings.

## Validating models and sizes up front

Different models support different sizes. Call `GetSupportedModelsAsync` to read the resolved model and its constraints before generating. This lets you fail early with a clear message instead of getting a wrong-ratio result:

{% code title="Validate.cs" %}

```csharp
#pragma warning disable UMBRACOAI_IMAGEGEN

var supported = await _imageGenerationService.GetSupportedModelsAsync(
    img => img.WithProfile("marketing-images"));

var boundModel = supported.Models.First(m => m.Model.ModelId == supported.ModelId);

// Per-model constraints are exposed via descriptor metadata
if (boundModel.Metadata.TryGetValue("image.supportedSizes", out var sizes))
{
    // e.g. "1024x1024,1024x1536,1536x1024"
    Console.WriteLine($"{supported.ModelId} supports: {sizes}");
}
```

{% endcode %}

Constraint metadata keys include `image.supportedSizes`, `image.maxEdge`, `image.supportsEdit`, and `image.supportsMask`.

## Observability

`GenerateImagesAsync` runs through the full middleware pipeline — usage tracking, audit entries, and telemetry — and publishes `AIImageGenerationExecutingNotification` / `AIImageGenerationExecutedNotification`. Every generation call requires an alias (`.WithAlias(...)`) so it can be attributed in analytics and audit logs.

## Related

* [Image Generation overview](/ai-in-umbraco/19.latest/using-the-api/image-generation.md) - Enablement and service surface
* [Editing Images](/ai-in-umbraco/19.latest/using-the-api/image-generation/editing-images.md) - Maskless edit and masked outpainting
* [Usage Analytics](/ai-in-umbraco/19.latest/backoffice/usage-analytics.md) - Where generations are recorded


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/ai-in-umbraco/19.latest/using-the-api/image-generation/generating-images.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
