Build an App with Vision Capabilities
30-second answer
A lightweight vision app reads an image file, encodes it as base64 and sends it to a multimodal model deployment (such as GPT-4.1) through the Foundry SDK, with an input_image part next to an input_text question in responses.create. The model's reply comes back in response.output_text. For fixed outputs like captions, tags and OCR, Azure Vision in Foundry Tools image analysis is the lighter alternative.
Exam objective: 2.3.3 Build a lightweight application that includes vision capabilities. (Skills measured as of April 15, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Use a <strong>multimodal</strong> deployment such as gpt-4.1-mini, which accepts images as well as text.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Use a multimodal deployment such as gpt-4.1-mini, which accepts images as well as text.
- Attach a photo with the 📎 button and ask a question about it.
- In code, send an input_image part (a URL or base64 data) next to the input_text.
- Models reason about images; Azure Vision returns structured results.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Computer vision
A photo goes in. Vision models return a caption, tags, objects with boxes, and any printed or handwritten text (OCR). A multimodal chat model can also answer questions about the picture.
🤔 What happens if…
Read this tour as text
- Five workload lanes. Most AI apps fall into a few workloads: generative and agentic AI, text analysis, speech, computer vision and information extraction. Each lane here takes a different kind of input and turns it into something useful.
- Text analysis. A hotel review goes in. Azure Language returns the sentiment (positive, neutral, negative), key phrases, named entities (people, places, dates), PII and a short summary.
- Speech to text. Speech recognition turns spoken audio into text: live captions, call transcripts, voice commands. It can also translate speech into another language as you talk.
- Text to speech. Speech synthesis turns text into natural speech with a neural voice. SSML lets you control speed, pitch and pauses. Think audiobooks, voice assistants and accessibility readers.
- Computer vision. A photo goes in. Vision models return a caption, tags, objects with boxes, and any printed or handwritten text (OCR). A multimodal chat model can also answer questions about the picture.
- Image generation. Image-generation models work the other way round: a text prompt goes in and a brand-new image comes out. Guardrails block harmful requests, and generated images are marked with content credentials.
- Extract from documents. Azure Content Understanding reads an invoice and returns fields you defined (vendor, date, total) with a confidence score for each, so low-confidence values can go to a person.
- Extract from audio and video. The same service handles media: an audio call becomes a transcript with speakers and a summary; a video is split into segments with key frames, descriptions and chapters.
Ask a multimodal model about a photo, generate a brand-new image from a prompt, then do both from a Python app.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Your warehouse app must flag damaged parcels from photos.
😊 THE SOLUTION
A small app that sends each photo to a multimodal deployment.
- Manual photo review✓ Automatic description
- Need a yes/no flag✓ Ask a focused question
- Need fixed tags or OCR✓ Azure Vision image analysis
Start with a question
Could my phone tell me if a plant leaf is diseased just from a photo?
Ravi grows tomatoes on a small farm near Nashik. Some leaves have brown spots and he doesn’t know if it’s a fungus or just too much sun.
What he wants is simple: snap a photo, ask “What’s wrong with this leaf?”, get a short answer. Behind that is a tiny app that sends the photo and the question to a multimodal model in Microsoft Foundry and prints the reply. You can write that app in about 20 lines of Python.
Explain it like I’m 10
The technical explanation
A lightweight vision app does four things: load an image, encode it, send it with a question to a multimodal deployment, and read the answer. You test the prompt first in the chat playground (attach an image, ask a question), then use View code to get a starting script.
-
1 Load
Read the photo file from disk or a camera.
-
2 Encode
Base64-encode it into a data URL.
-
3 Send
responses.create with input_text and input_image.
-
4 Read
Print response.output_text or save it.
What you need
- A Foundry project with a multimodal model deployed, such as GPT-4.1, GPT-4.1-mini or GPT-4o.
- The project endpoint in an environment variable,
FOUNDRY_PROJECT_ENDPOINT. - Signed in with
az loginand the Foundry User role on the project. The AIProjectClient uses Microsoft Entra ID only, so there’s no key in the code.
The app
# vision_app.py
# 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(),
)
openai = project.get_openai_client()
# 1. Load and encode the photo as a data URL
with open("leaf.jpg", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode("utf-8")
data_url = f"data:image/jpeg;base64,{image_b64}"
# 2. Send the question and the image together
response = openai.responses.create(
model="gpt-4.1-mini", # your multimodal deployment name
instructions="You help farmers. Answer in two short sentences.",
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "What might be wrong with this tomato leaf?"},
{"type": "input_image", "image_url": data_url},
],
}],
)
# 3. Read the answer
print(response.output_text)
A few things to notice:
modelis the deployment name, not the model family.- The image can be a data URL (as above) or a public https URL.
instructionsworks like a system message. Use it to control tone and length, or to ask for JSON your app can parse.- You can loop and ask follow-up questions with
previous_response_idor a conversation, just like a chat app.
The alternative: Azure Vision image analysis
Not every vision task needs a prompt. Azure Vision in Foundry Tools image analysis returns fixed, structured results: a caption, dense captions, tags, detected objects and people, smart-crop suggestions and printed or handwritten text with OCR (Read). It uses its own SDK (azure-ai-vision-imageanalysis) and returns the same JSON shape every time.
| Need | Pick |
|---|---|
| Ask a different question about each photo, explain a chart, compare two images | Multimodal model via the Foundry SDK |
| Same caption and tags for millions of catalogue photos | Azure Vision image analysis |
| Read the text on a sign or a label | Azure Vision OCR (Read), or a multimodal model for a quick one-off |
| Pull named fields from images into a schema you define | Content Understanding |
Architect level Image size, tokens and detail
Images are turned into tokens before the model sees them, and bigger images cost more tokens. Resize phone photos (often 4,000 pixels wide) to something like 1,024 pixels on the long side before sending, unless tiny details matter. Some models accept a detail setting (low, high, auto) on the image part; low is cheaper and fine for “what’s in this photo?” questions. Keep sensitive photos in mind too: guardrails apply to image inputs, and you should tell users what happens to the pictures they upload.
Real-world business scenario
Contoso Insurance, Pune
- The problem
- Claim handlers spent hours reading customer photos of minor home damage before deciding who should visit.
- What they used
- A small Python service sends each claim photo to a GPT-4.1-mini deployment in Foundry with instructions to describe the damage and rate it minor, moderate or severe in JSON, and stores the result with the claim.
- Why that choice
- The question needs judgement about each photo, which a multimodal model handles, and Entra ID authentication keeps keys out of the code.
- The result
- Handlers now start each claim with a one-line damage summary and spend their time on the severe cases first.
When to use it and when not to
✓ Use it when…
- Apps that ask open questions about photos, screenshots, charts or diagrams.
- Quick prototypes: test in the playground, then View code and extend the script.
- Answers that need judgement or explanation, not just a label.
✕ Think twice when…
- High-volume, fixed outputs like captions, tags or OCR. Azure Vision image analysis is cheaper and more predictable.
- Pulling the same named fields out of thousands of images or forms. Use Content Understanding.
- Decisions with legal or safety impact without a person checking the answer.
↔ Alternatives to consider
- **Azure Vision in Foundry Tools** for captions, tags, objects and OCR.
- **Content Understanding** for structured fields with confidence scores.
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.
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 does a Python app send a photo to a model in Foundry?
Model answer
It reads the file, base64-encodes it and builds a data URL. Then it calls responses.create on the OpenAI client from the AIProjectClient, with a user message that has an input_text part for the question and an input_image part for the photo. The answer is in response.output_text.
Interviewer follows up
Can you send an image URL instead?
You
Yes. If the image is reachable over https, I put that URL in image_url instead of a data URL.
Intermediate When would you use Azure Vision image analysis instead of a multimodal model?
Model answer
When I need the same structured output every time, like a caption, a tag list or the printed text from OCR, at high volume. Image analysis gives predictable JSON. A multimodal model is better when the question changes, like "Is this shelf fully stocked?" or "Explain this chart".
Experienced developer How do you keep a vision app secure and cheap?
Model answer
I use DefaultAzureCredential with the Foundry User role instead of keys in code, keep the endpoint in an environment variable, and resize large photos before sending them because big images use more tokens. I also give the model clear instructions and ask for short or JSON answers so the app can parse them.
Scenario A warehouse wants staff to photograph damaged boxes and get a short damage report. How would you build it?
Model answer
A small Python or web app takes the photo, sends it with instructions like "Describe any visible damage in one sentence and rate it minor, moderate or severe" to a multimodal deployment, and saves the reply with the order number. I'd test the prompt in the playground first and use View code to start the app.
Quick revision
Key points
- A vision app sends an image plus a question to a multimodal model deployment and reads the text reply.
- With the Foundry SDK, get the OpenAI client from AIProjectClient and call responses.create.
- The image goes in an input_image part as a base64 data URL or an https URL.
- The model parameter is the deployment name, and auth uses Microsoft Entra ID (DefaultAzureCredential).
- Azure Vision image analysis is the alternative for fixed captions, tags, objects and OCR.
Important terminology
- Multimodal model
- A model that accepts more than one kind of input, such as text and images, in the same prompt.
- input_image
- The content part in a Responses API message that carries an image as a data URL or an https URL.
- Data URL
- A string like data:image/jpeg;base64,... that embeds a file's bytes directly in the request.
- Azure Vision in Foundry Tools
- The image analysis service that returns captions, tags, objects, people and OCR text from images.
- DefaultAzureCredential
- An Azure Identity class that signs your app in with Microsoft Entra ID, using az login on your own machine.
Common mistakes
- Sending an image to a text-only model. The deployment must be multimodal.
- Putting a raw file path in image_url. It needs a data URL or a public https URL.
Exam tips
- "Ask a question about a photo from a Python app" = multimodal model + input_image in the Foundry SDK.
- "Captions, tags or read printed text with no prompt" = Azure Vision image analysis.
Five quick revision questions
-
1.Which content part carries the photo in the Responses API?Show
input_image.
-
2.Where is the model's answer?Show
response.output_text.
-
3.What does the model parameter hold?Show
The deployment name.
-
4.Which credential does AIProjectClient use?Show
Microsoft Entra ID, for example DefaultAzureCredential.
-
5.Which service gives captions, tags and OCR without a prompt?Show
Azure Vision in Foundry Tools (image analysis).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Content Understanding for Documents and Forms
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.