Lesson 19 of 26 · see all lessons
  1. Start here: the exam, Python basics and responsible AI (skill area 1, 40-45%)

    1. 1. Start here: the AI-901 exam, the plan and what you already know
    2. 2. The Python and Azure basics AI-901 expects
    3. 3. Responsible AI: the six principles in practice
  2. AI models: how they work, choosing and deploying (skill area 1)

    1. 4. How generative AI models work
    2. 5. Choosing the right AI model for the job
    3. 6. Deploying a model: deployment options and configuration parameters
  3. AI workloads: text, speech, vision and extraction (skill area 1)

    1. 7. Common AI workloads: from chat and agents to vision and extraction
    2. 8. Text analysis: key phrases, entities, sentiment and summaries
    3. 9. Speech: recognition and synthesis
    4. 10. Computer vision and image generation
    5. 11. Extracting information from documents, images, audio and video
  4. Generative AI apps and agents in Foundry (skill area 2, 55-60%)

    1. 12. Writing system and user prompts
    2. 13. Deploying a model and chatting with it in the Foundry portal
    3. 14. Building a lightweight chat client with the Foundry SDK
    4. 15. Creating and testing a single agent in the Foundry portal
    5. 16. Building a lightweight client app for an agent
  5. Text, speech, vision and extraction apps in Foundry (skill area 2)

    1. 17. Building a text analysis app
    2. 18. Building speech apps: spoken prompts and Azure Speech
    3. 19. Building vision apps: images in prompts and generated images
    4. 20. Extracting information with Content Understanding: documents and forms
    5. 21. Content Understanding for images, audio and video, and a small extraction app
  6. Final review and four mock exams

    1. 22. Final review and exam day: every decision on one page
    2. 23. Mock exam 1
    3. 24. Mock exam 2
    4. 25. Mock exam 3
    5. 26. Mock exam 4
See the leaderboard

18 min

Building vision apps: images in prompts and generated images

Send images to a multimodal model, generate new images, and read a small vision app.

By the end of this lesson you can

  • Read a Responses API call that sends an image with a text prompt
  • Read an image-generation call and name its size, quality and output options
  • Generate an image in the Foundry images playground
  • Choose between a multimodal model, an image model and Azure Vision

From earlier lessons · 1 of 2

Your Speech SDK app must read its reply in a different voice. Which line changes?

Pick one answer.

From earlier lessons · 2 of 2

Which computer vision task returns a box around each item it finds in a photo?

Pick one answer.

A Fernhill Travel guide sends a photo of a broken coach seat and asks what the repair team should know. Marketing wants a fresh poster for the Lisbon tour by Friday, and nobody on the team can draw. One feature reads a picture; the other makes one. Both run on models you deploy in Foundry.

[2]

Images in a prompt

Exam depth: know it cold.

A vision-capable model reads images and text together. It can recognize objects, shapes, colors and textures, and read text in the image. Many chat models in Foundry are vision-capable, such as gpt-5-mini.

In the Responses API, a user message has a list of content parts. Text goes in an input_text part. An image goes in an input_image part, as one of these:

  • A public image URL.
  • A base64 data URL, such as data:image/jpeg;base64,..., for a local file.
  • A file ID from the Files API.

PNG, JPEG, WebP and non-animated GIF are supported. An optional detail of low, high or auto trades speed for fine detail.

[34][102]

Rendering diagram…
A local photo becomes a base64 data URL. It travels with the text in one user message, and the answer comes back as text.

[102]

Read the code: a lightweight vision app

python
import os
import base64
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
project = AIProjectClient(
endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
credential=DefaultAzureCredential(),
)
openai = project.get_openai_client()
with open("coach_seat.jpg", "rb") as image_file:
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
response = openai.responses.create(
model="gpt-5-mini", # your vision-capable deployment
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "What damage do you see? One sentence."},
{"type": "input_image", "image_url": f"data:image/jpeg;base64,{base64_image}"},
],
}],
)
print(response.output_text)
Output: one sentence such as "The seat cushion is torn along the front edge and the foam is exposed." Wording varies.

[18][102]

Exam depth: know it cold.

  • Lines 6-10 create the AIProjectClient and get an OpenAI client, exactly as in lesson 14.
  • Lines 12-13 read the photo and encode it as base64 text.
  • Line 16 passes the deployment name. The model must be vision-capable.
  • Lines 17-23 send input as a list with one user message. Its content holds two parts: the question as input_text and the photo as input_image.
  • Line 21 builds the data URL: data:, the image type, ;base64, and the encoded bytes.
  • Line 25 prints output_text, the model's answer.

For an image already online, put its URL in image_url instead and skip the encoding.

[102]

The vision app must describe a photo already published at a public web address. What should the input_image part's image_url contain?

Pick one answer.

[102]

[102][121]

Generating new images

Exam depth: know it cold.

An image-generation model creates a new picture from a text prompt. In Foundry these are the GPT-image models, such as gpt-image-1 and gpt-image-2. They also accept an image as input, so they can edit a picture, for example with inpainting: you mask an area and describe what goes there.

You deploy the image model, then call the images API with your prompt. Key options:

  • size, such as 1024x1024 or 1536x1024 for landscape.
  • quality: low, medium or high. Higher looks better but is slower.
  • n: how many images, 1 to 10.

GPT-image models return the picture as base64 data, not a link.

[86]

python
import os
import base64
from openai import AzureOpenAI
client = AzureOpenAI(
api_version="2025-04-01-preview",
api_key=os.environ["AZURE_OPENAI_API_KEY"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
)
result = client.images.generate(
model="gpt-image-1", # your image model deployment name
prompt="A watercolor poster of a yellow tram climbing a sunny Lisbon hill",
n=1,
size="1024x1024",
quality="high",
output_format="png",
)
image_base64 = result.data[0].b64_json
with open("lisbon_poster.png", "wb") as image_file:
image_file.write(base64.b64decode(image_base64))
Output: a 1024 by 1024 PNG saved as lisbon_poster.png. Generation typically takes 10 to 30 seconds.

[86]

Exam depth: know it cold.

  • Lines 5-9 create an AzureOpenAI client from the endpoint and key in environment variables.
  • Line 11 calls client.images.generate.
  • Line 12 passes your image deployment name as model.
  • Line 13 is the prompt, the description of the picture you want.
  • Lines 14-17 ask for one image, square, high quality, as PNG.
  • Lines 20-22 read result.data[0].b64_json and decode it into an image file.

[86]

Marketing says the generated posters look good but take too long during a live demo. They accept slightly lower detail. Which option should you change in the images.generate call?

Pick one answer.

[86]

Asked for "a sunny Lisbon tram". Got a sunny Lisbon tram. Forgot to say "no dragons on the roof". Picture: Claymation-style scene, soft studio lighting.

Try it in the Foundry portal: the images playground

Exam depth: recognize it.

  1. Sign in to the Foundry portal and open your project.
  2. Deploy an image-generation model from the model list.
  3. On the model's page, select Open in playground.
  4. In the Images playground, type a prompt and select Generate.
  5. Change size or quality and generate again to compare.
  6. Select View code to see Python prefilled with your settings.
  7. When you finish, delete the deployment or resource group to stop costs.

If your prompt is flagged as harmful, no image comes back.

[86]

Put in order

Put the images playground steps in order.

Drag, or focus an item and press Space, move with the arrow keys, then Space to drop.

  1. Deploy an image-generation model
  2. Open your project in the Foundry portal
  3. Select Open in playground on the model's page
  4. Type a prompt and select Generate
  5. Select View code to copy the Python
  6. Delete the deployment when you finish

[86]

Content filters on images

Exam depth: recognize it.

Guardrails, also called content filters, apply at the deployment. They check both what goes in and what comes out.

  • Image input: images that break content policies are rejected, like harmful text prompts.
  • Image output: if the prompt is flagged, the service returns an error with the code contentFilter and no image. The generated image itself can also be filtered.

Photorealistic images of minors are blocked by default. This is responsible AI in practice: reliability and safety.

[86][102]

Which vision tool fits?

Exam depth: know it cold.

NeedBest fitWhy
Describe or answer questions about a photo.Vision-capable model, input_image.Flexible answers in your own words.
Create a new picture or edit one from a prompt.Image-generation model.Only these models output images.
Fixed tags, captions or object boxes with scores.Azure Vision Image Analysis.Prebuilt, structured results.
Read text in scanned documents.Document Intelligence Read.Built for text-heavy pages.

Azure Vision Image Analysis is now marked legacy and retires on September 25, 2028. Microsoft points new image-understanding work to GPT models in Foundry and to Azure Content Understanding.

Decision rule: image in, text out: vision-capable model. Image out: image-generation model.

[84][86][102]

Fernhill Travel wants a short, friendly description of each guide's trip photo for its blog, in the brand's tone. The team already has a chat deployment that accepts images. What should you use?

Pick one answer.

[102]

Exam-style practice

A travel firm needs ten different banner ideas for a hiking tour, created from a written brief. The solution must use a model deployed in Foundry. What should you use?

Pick one answer.

[86]

For each statement, select Yes if it is true. Statement: to send a local photo to a vision-capable model in the Responses API, you put its file path in the image_url value.

Pick one answer.

[102]

In the image-generation app, what does result.data[0].b64_json hold?

Pick one answer.

[86]

FlashcardsIndex cardsFlashcards ⚡

Card 1 of 16

[84][86][102]

Worth keeping

  1. Image in a prompt: an input_image part next to an input_text part in one user message.
  2. Local photo: base64 data URL. Online photo: its public URL.
  3. New pictures: images.generate on an image model, with size, quality and n; read b64_json.
  4. Image in, text out: vision-capable model. Image out: image-generation model.
  5. Content filters check image input and output at the deployment.

On the job

Ask the vision model for structured answers, such as "damage type, location, severity", so a repair team can sort reports. Use detail: low for quick triage and high when small text or fine damage matters. For marketing images, keep a short style guide in your prompt and review every image before it goes public.

[102]

Pictures are covered. Now the back office: staff still retype every booking form and supplier invoice by hand. Next lesson, Azure Content Understanding reads the form and hands you the fields.

Leaderboard

Loading…

50 XP for each lesson you finish, 10 for each right answer. Names show only for learners who turn on Show me on leaderboards.

Embed this practice on your site

Free for classrooms, blogs and study groups. Paste this into any page that accepts HTML.

Report a copyright problem with this lesson

Sources for this lesson (7)

Each fact in the lesson is marked with the number of the page it comes from.

  1. [2]Microsoft Learn: Study guide for Exam AI-901: Microsoft Azure AI Fundamentals
  2. [18]Microsoft Learn: Quickstart: Get started with Microsoft Foundry SDK
  3. [34]Microsoft Learn: Foundry Models sold by Azure
  4. [84]Microsoft Learn: Migrate from Azure Vision in Foundry Tools - Image Analysis
  5. [86]Microsoft Learn: How to use image generation models from OpenAI
  6. [102]Microsoft Learn: Use the Azure OpenAI Responses API
  7. [121]Microsoft Learn: How to use vision-enabled chat models