Lesson 19 of 26 · see all lessons
Start here: the exam, Python basics and responsible AI (skill area 1, 40-45%)
AI models: how they work, choosing and deploying (skill area 1)
AI workloads: text, speech, vision and extraction (skill area 1)
Generative AI apps and agents in Foundry (skill area 2, 55-60%)
Text, speech, vision and extraction apps in Foundry (skill area 2)
- 17. Building a text analysis app
- 18. Building speech apps: spoken prompts and Azure Speech
- 19. Building vision apps: images in prompts and generated images
- 20. Extracting information with Content Understanding: documents and forms
- 21. Content Understanding for images, audio and video, and a small extraction app
Final review and four mock exams
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.
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.
Read the code: a lightweight vision app
import osimport base64from azure.identity import DefaultAzureCredentialfrom azure.ai.projects import AIProjectClientproject = 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 deploymentinput=[{"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)
Exam depth: know it cold.
- Lines 6-10 create the
AIProjectClientand 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
inputas a list with one user message. Itscontentholds two parts: the question asinput_textand the photo asinput_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.
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.
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 as1024x1024or1536x1024for landscape.quality:low,mediumorhigh. 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.
import osimport base64from openai import AzureOpenAIclient = 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 nameprompt="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_jsonwith open("lisbon_poster.png", "wb") as image_file:image_file.write(base64.b64decode(image_base64))
Exam depth: know it cold.
- Lines 5-9 create an
AzureOpenAIclient 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_jsonand decode it into an image file.
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.
Try it in the Foundry portal: the images playground
Exam depth: recognize it.
- Sign in to the Foundry portal and open your project.
- Deploy an image-generation model from the model list.
- On the model's page, select Open in playground.
- In the Images playground, type a prompt and select Generate.
- Change size or quality and generate again to compare.
- Select View code to see Python prefilled with your settings.
- When you finish, delete the deployment or resource group to stop costs.
If your prompt is flagged as harmful, no image comes back.
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.
- Deploy an image-generation model
- Open your project in the Foundry portal
- Select Open in playground on the model's page
- Type a prompt and select Generate
- Select View code to copy the Python
- Delete the deployment when you finish
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
contentFilterand 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.
Which vision tool fits?
Exam depth: know it cold.
| Need | Best fit | Why |
|---|---|---|
| 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.
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.
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.
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.
In the image-generation app, what does result.data[0].b64_json hold?
Pick one answer.
Worth keeping
- Image in a prompt: an input_image part next to an input_text part in one user message.
- Local photo: base64 data URL. Online photo: its public URL.
- New pictures: images.generate on an image model, with size, quality and n; read b64_json.
- Image in, text out: vision-capable model. Image out: image-generation model.
- 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.
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.
- [2]Microsoft Learn: Study guide for Exam AI-901: Microsoft Azure AI Fundamentals
- [18]Microsoft Learn: Quickstart: Get started with Microsoft Foundry SDK
- [34]Microsoft Learn: Foundry Models sold by Azure
- [84]Microsoft Learn: Migrate from Azure Vision in Foundry Tools - Image Analysis
- [86]Microsoft Learn: How to use image generation models from OpenAI
- [102]Microsoft Learn: Use the Azure OpenAI Responses API
- [121]Microsoft Learn: How to use vision-enabled chat models