Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 25 of 30
❮Prev Next❯

Generate Images with Generative Models

Module 2: Microsoft Foundry ⏱ 8 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    You create new visual output by deploying an image-generation model such as gpt-image-1 in Microsoft Foundry and sending it a text prompt, either in the images playground or from code with images.generate. You choose the size and quality, the model returns the picture as base64 data, and guardrails check the prompt and the image while content credentials mark the result as AI-generated.

    Simulate it » No Azure account needed

    Exam objective: 2.3.2 Create new visual outputs by using generative models. (Skills measured as of April 15, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Generate an image with gpt-image-1 Deploy an image model and generate a poster.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Deploy an <strong>image-generation</strong> model: <strong>gpt-image-1</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Deploy an image-generation model: gpt-image-1.
    2. Describe the subject, style, colours, mood and layout. Specific prompts give better images.
    3. The result appears in the playground. You can edit it with a follow-up prompt.
    4. In code: images.generate returns the image as base64.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    Marketing needs 50 festival banners by Friday.

    😊 THE SOLUTION

    Generate drafts from text prompts, then polish the best.

    • Designers overloaded✓ Generate first drafts
    • Is it AI-made?✓ Content credentials
    • Risky requests✓ Guardrails screen prompts
    🛠️ Solved with: gpt-image-1

    Start with a question

    Can I get a festival poster made in a minute without hiring a designer?

    Priya runs a small sweet shop in Madurai. Diwali is two weeks away and she wants a poster with a plate of laddoos, diyas and the words “Diwali Specials”. A designer would take a few days.

    She types one sentence describing the poster, and a few seconds later there’s a brand-new picture that never existed before. That’s an image-generation model at work, and in Microsoft Foundry the one you’ll use is gpt-image-1.

    Explain it like I’m 10

    The technical explanation

    An image-generation model turns a text prompt into a new image. In Foundry the main choice is gpt-image-1 from OpenAI (DALL-E 3 is the older model you may still see). It’s a different job from vision: a multimodal model reads an image you give it, while an image model creates one.

    Step 1: try it in the images playground

    1. In your Foundry project, open the model catalog, find gpt-image-1 and deploy it. Some image models need an access request before the deploy button works.
    2. Open the Images playground, pick your deployment and type a prompt.
    3. Set the size and quality, then generate. Change one thing at a time and compare.
    4. Use View code to see the same request as Python.
    SettingWhat it doesValues you’ll see
    SizeShape and resolution of the picture1024x1024 (square), 1536x1024 (landscape), 1024x1536 (portrait), auto
    QualityDetail level, which affects time and costlow, medium, high (or auto)
    Number of imagesHow many variations per requestn in code

    Step 2: generate from code

    You use the same Foundry SDK as for chat. The model value is your deployment name.

    # pip install "azure-ai-projects>=2.3.0" azure-identity
    import base64, os
    from azure.identity import DefaultAzureCredential
    from azure.ai.projects import AIProjectClient
    
    project = AIProjectClient(
        endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
        credential=DefaultAzureCredential(),   # uses your az login
    )
    openai = project.get_openai_client()
    
    result = openai.images.generate(
        model="gpt-image-1",            # your deployment name
        prompt="A festive poster: a brass plate of laddoos surrounded by glowing diyas, "
               "warm golden light, the words 'Diwali Specials' in bold at the top",
        size="1024x1536",               # portrait poster
        quality="medium",
    )
    
    # gpt-image-1 returns base64 data, so decode it and save a PNG
    with open("poster.png", "wb") as f:
        f.write(base64.b64decode(result.data[0].b64_json))

    Writing prompts that work

    • Subject first, then setting, style, lighting and camera angle: “close-up product photo, white background, soft studio light”.
    • Spell out any text you want on the image and keep it short. Long sentences in images still go wrong sometimes.
    • Say the layout: “logo in the top-left corner, empty space on the right for a price”.
    • Iterate. Keep the prompt that worked and change one detail per try.

    Editing an existing image

    gpt-image-1 can also edit. You send an image plus an instruction such as “replace the background with a beach at sunset”, and you can add a mask so only part of the picture changes (often called inpainting). In code that’s images.edit instead of images.generate; in the playground you upload an image and describe the change.

    1. 1 Prompt

      Your text, size and quality go to the deployment.

    2. 2 Prompt check

      Guardrails check the prompt for harmful content.

    3. 3 Generate

      gpt-image-1 creates the image.

    4. 4 Output check

      Guardrails check the image itself.

    5. 5 Credentials

      C2PA content credentials are attached, then the image is returned.

    What happens to one image request

    Guardrails and content credentials

    Foundry guardrails (content filters) check image prompts and the generated images for hate, sexual, violence and self-harm content. If something’s blocked, the request fails with a content-filter error instead of returning an image, and your app should show a friendly message. Every generated image also carries content credentials: signed C2PA metadata saying it was made with AI, so a newspaper or a customer can check where it came from.

    Architect level Cost and speed trade-offs

    Image generation is billed per image, and the price depends on size and quality, so high quality at a large size costs the most. A sensible pattern is to draft at low or medium quality, pick the best prompt, then generate the final at high. Generation takes a few seconds to tens of seconds, so web apps usually show a spinner or run the request in the background rather than blocking the page.

    Real-world business scenario

    Travel and tourism

    Fabrikam Travels, a Bengaluru travel agency

    The problem
    The team needed fresh banner images for 40 holiday packages every season, and stock photos looked the same as every competitor's.
    What they used
    Deployed gpt-image-1 in a Foundry project and built a small script that fills a prompt template with each destination, season and layout, generating drafts at medium quality and finals at high quality.
    Why that choice
    A prompt template keeps the brand style consistent, guardrails block unsafe requests, and content credentials keep the agency honest about AI-made images.
    The result
    Banner drafts that used to take a designer a week now take an afternoon, and the designer spends that time picking and polishing the best ones.

    When to use it and when not to

    ✓ Use it when…

    • Marketing drafts, posters, social images and concept art where a new picture is needed.
    • Product mock-ups and storyboards to show an idea before paying for a photo shoot.
    • Quick edits to an existing image, like swapping a background, using image editing.

    ✕ Think twice when…

    • Understanding or describing an existing photo. Use a multimodal model or Azure Vision instead.
    • Images that must be factually exact, like a real person, a real product label or a technical diagram.
    • Anything published without human review.

    ↔ Alternatives to consider

    • **A multimodal model** (GPT-4.1, GPT-4o) to read and describe images.
    • **Azure Vision in Foundry Tools** for captions, tags and text (OCR) from images.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AI-901 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    A retail company wants to create original promotional images from short text descriptions written by its marketing team. The solution must be built in Microsoft Foundry.

    Which type of model should the company deploy?

    Question 2

    Question 2 of 5

    You call images.generate by using the OpenAI client obtained from an AIProjectClient. Which value must you pass in the model parameter?

    Question 3

    Question 3 of 5 · Select 2

    Which TWO settings can you specify when you generate an image with gpt-image-1?

    Question 4

    Question 4 of 5

    A news organization needs a way to verify whether an image published by a partner was created by an Azure OpenAI image model. Which feature supports this requirement?

    Question 5

    Question 5 of 5

    A designer likes a generated product image but wants only the background replaced with a beach scene. What should the designer do?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner How do you generate an image with Microsoft Foundry?

    Model answer

    I deploy an image model like gpt-image-1 in my Foundry project, open the images playground and type a prompt describing the picture. From code I call images.generate on the OpenAI client I get from the project, passing the deployment name, the prompt and a size.

    Interviewer follows up

    What comes back from the API?

    You

    A list of images, each as base64 data in b64_json. I decode it and save it as a PNG file.

    Intermediate What makes a good image prompt?

    Model answer

    Be specific about the subject, setting, style, lighting and layout, and say what text should appear if any. "A watercolour poster of a Chennai beach at sunrise, wide shot, soft orange light, the words Marina Run 2026 at the top" works far better than "beach poster". If the first result is close, I tweak one detail at a time.

    Experienced developer How do responsible AI controls apply to image generation?

    Model answer

    Foundry guardrails check the prompt before generation and the image after it, for categories like hate, sexual, violence and self-harm, and the request fails with a content-filter error if something is blocked. Generated images also carry content credentials, so people downstream can see the image was AI-generated. I'd still add human review before anything goes into a public campaign.

    Scenario A marketing team wants 20 banner variations for a festival sale but keeps getting images with the wrong layout. What do you suggest?

    Model answer

    I'd fix the size to the banner shape, like 1536x1024 for landscape, and write a prompt template that spells out layout, colours and text placement, changing only the product and offer per variation. For small fixes on an image they like, I'd use image editing instead of regenerating from scratch.

    Quick revision

    Key points

    • Image-generation models create new images from text prompts; gpt-image-1 is the current OpenAI model in Foundry.
    • Test in the images playground first, then call images.generate from code with the deployment name.
    • Size and quality are the main settings; higher quality takes longer and costs more.
    • gpt-image-1 can also edit an existing image from an instruction, optionally with a mask.
    • Guardrails filter harmful prompts and outputs, and content credentials label images as AI-generated.

    Important terminology

    Image-generation model
    A generative model that creates a new image from a text prompt, such as gpt-image-1.
    gpt-image-1
    An OpenAI image model in Foundry that generates new images and edits existing ones from text instructions.
    Images playground
    The Foundry portal page where you type a prompt, pick size and quality, and see generated images without writing code.
    Image editing (inpainting)
    Changing part of an existing image from a text instruction, optionally limited to a masked area.
    Content credentials
    Signed C2PA provenance metadata added to generated images so anyone can check they were made with AI.

    Common mistakes

    • Sending an image-generation request to a chat model deployment. You need an image model deployment.
    • Thinking a vision model creates images. Vision models read images; image-generation models make them.

    Exam tips

    • "Create a new image from a description" = an image-generation model such as gpt-image-1.
    • "Prove an image was AI-generated" = content credentials (C2PA provenance).

    Five quick revision questions

    1. 1.Which model creates images from text in Foundry?Show

      gpt-image-1 (DALL-E 3 is the older option).

    2. 2.Which method generates an image in Python?Show

      images.generate on the OpenAI client from the project.

    3. 3.How is the generated image returned?Show

      As base64 data in data[0].b64_json.

    4. 4.What checks harmful image prompts?Show

      Foundry guardrails (content filters).

    5. 5.What marks an image as AI-generated?Show

      Content credentials (C2PA provenance metadata).

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Build an App with Vision Capabilities

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.