Your profile

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

Lesson 26 of 30
❮Prev Next❯

Build an App with Vision Capabilities

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

    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.

    Simulate it » No Azure account needed

    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.

    Azure portal: Ask a multimodal model about an image Test in the playground, then View code.
    </> Embed

    Embed this simulation

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

    Loading the portal…

    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
    1. Use a multimodal deployment such as gpt-4.1-mini, which accepts images as well as text.
    2. Attach a photo with the 📎 button and ask a question about it.
    3. In code, send an input_image part (a URL or base64 data) next to the input_text.
    4. 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.

    😟 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
    🛠️ Solved with: Vision app

    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. 1 Load

      Read the photo file from disk or a camera.

    2. 2 Encode

      Base64-encode it into a data URL.

    3. 3 Send

      responses.create with input_text and input_image.

    4. 4 Read

      Print response.output_text or save it.

    The vision app loop

    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 login and 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:

    • model is the deployment name, not the model family.
    • The image can be a data URL (as above) or a public https URL.
    • instructions works 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_id or 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.

    NeedPick
    Ask a different question about each photo, explain a chart, compare two imagesMultimodal model via the Foundry SDK
    Same caption and tags for millions of catalogue photosAzure Vision image analysis
    Read the text on a sign or a labelAzure Vision OCR (Read), or a multimodal model for a quick one-off
    Pull named fields from images into a schema you defineContent 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

    Insurance

    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.
    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

    You are building a Python app that sends a photo and a question to a deployed GPT-4.1 model by using the Responses API. Which content part type should contain the photo?

    Question 2

    Question 2 of 5 · Select 2

    Which TWO formats can you use to supply an image in the image_url value of an input_image part?

    Question 3

    Question 3 of 5

    Your vision app creates an AIProjectClient. Which authentication method does the client support?

    Question 4

    Question 4 of 5

    An online store needs a caption and a list of tags for each of two million catalogue photos. The output format must be identical for every photo, and no user questions are involved.

    Which service is the most appropriate?

    Question 5

    Question 5 of 5

    After calling responses.create with an image and a question, which property contains the model's text answer?

    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. 1.Which content part carries the photo in the Responses API?Show

      input_image.

    2. 2.Where is the model's answer?Show

      response.output_text.

    3. 3.What does the model parameter hold?Show

      The deployment name.

    4. 4.Which credential does AIProjectClient use?Show

      Microsoft Entra ID, for example DefaultAzureCredential.

    5. 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

    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.