Your profile

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

Lesson 12 of 39
❮Prev Next❯

Deploy and Call Models from Your App

Module 2: GenAI & Agents ⏱ 11 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 deploy a model in Microsoft Foundry, which creates a named deployment with a model version, a deployment type and capacity. Your app calls the deployment name, never the model name, through the project endpoint with AIProjectClient and DefaultAzureCredential. Choose a large or reasoning model for hard work, a small language model for cheap, high-volume work, a code model for programming tasks and a multimodal model when the input is an image or audio.

    Simulate it » No Azure account needed

    Exam objective: 2.1.1 Deploy and consume LLMs, small models, code models and multimodal models. 2.1.6 Configure an application to connect to a Foundry project. (Skills measured as of April 16, 2026)

    Simulations

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

    Azure portal: Deploy a large and a small model, then call them Deploy a large and a small model and test them in the playground.
    </> Embed

    Embed this simulation

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

    Loading the portal…

    Open <strong>Build ➜ Models + endpoints</strong> and select <strong>+ Deploy model</strong>. A deployment is what your app calls.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open Build ➜ Models + endpoints and select + Deploy model. A deployment is what your app calls.
    2. Pick gpt-4.1-mini for general work. The deployment name is the name your code will use, so choose one that describes the job, not the model.
    3. Add a small language model for cheap, high-volume work such as labelling. Same project, a second deployment.
    4. Both deployments appear. Open support-chat to test it.
    5. In the chat playground pick the deployment, write instructions and ask a question. View code shows the same call as Python, using the project endpoint and keyless sign-in.

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

    😟 THE PROBLEM

    Every call goes to the biggest model, and one deploy broke the app because it used the model name.

    😊 THE SOLUTION

    Deploy the right model for each job and have the app call the deployment name.

    • Hard questions✓ A large or reasoning model deployment
    • Thousands of simple labels✓ A small language model deployment
    • A model upgrade breaks the app✓ Call the deployment name, so the model behind it can change
    🛠️ Solved with: Foundry model deployments

    Start with a question

    Why can a restaurant change its chef without reprinting the menu?

    The menu says “today’s special”, not “Ravi’s special”. The kitchen decides who cooks it. Customers keep ordering the same way, and the chef behind it can change.

    A deployment works like that menu line. Your app asks for support-chat. Behind the name sits one model, one version, one deployment type and a slice of capacity. Move the name to a new model next month and the app doesn’t change.

    Explain it like I’m 10

    The technical explanation

    Pick the model for the job

    NeedChooseWhy
    Hard, multistep problems, long documentsA large or reasoning model (gpt-4.1, o4-mini)Better answers on difficult work, higher cost and latency
    High-volume, simple tasks such as labellingA small language model (Phi-4-mini-instruct, gpt-4.1-nano)Fast and cheap
    Writing and fixing codeA code-capable modelTrained on programming tasks
    Images or audio as inputA multimodal model (gpt-4.1, Phi-4-multimodal-instruct)Accepts more than text
    Search and similarityAn embedding model (text-embedding-3-small)Returns vectors, not text

    Test two candidates on your own examples before you decide. Benchmarks don’t know your tickets.

    Deploy it

    In the Foundry portal go to Build > Models + endpoints > + Deploy model. You choose the model, a deployment name, the deployment type (Global Standard, Data Zone Standard, Standard, Provisioned or Batch), the model version and the capacity in tokens per minute. From the CLI:

    az cognitiveservices account deployment create -n contoso-agents -g rg-agents \
      --deployment-name support-chat --model-name gpt-4.1-mini --model-format OpenAI \
      --sku-name GlobalStandard --sku-capacity 50

    Deployment names must be unique in the resource. Pick names that describe the job, such as support-chat or label-fast.

    Call it from Python

    Install the Foundry SDK, then connect with the project endpoint and a keyless credential. Both values come from the project Overview page, and the endpoint belongs in an environment variable, not in code.

    # pip install "azure-ai-projects>=2.3.0" azure-identity
    import 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()          # OpenAI-compatible client
    
    r = openai.responses.create(model="support-chat",      # the DEPLOYMENT name
                                input="In one sentence, why do apps call a deployment name?")
    print(r.output_text, r.usage.input_tokens, r.usage.output_tokens)

    The reply carries the token counts you pay for. To run this in Azure without a key, enable a managed identity on the host and give it the Foundry User role on the Foundry resource. Locally, DefaultAzureCredential uses your own sign-in.

    Architect level Deployment types change where and how you pay

    Global Standard and Data Zone Standard bill per token and differ in where the prompt may be processed: anywhere, or inside a data zone. Standard stays in one region. Provisioned reserves capacity for steady, latency-sensitive traffic, and Batch suits big offline jobs. You choose the type when you deploy, so a residency rule is a deployment decision, not a code change. Model versions can be pinned or set to upgrade automatically, as of 25 November 2026.

    Real-world business scenario

    Retail

    Fabrikam Retail (fictional)

    The problem
    One app sent every request, even simple order-status labels, to the largest model. It was slow at peak, and a model upgrade once broke production because the code named the model.
    What they used
    Two Foundry deployments in one project: support-chat on gpt-4.1-mini for customer answers and label-fast on Phi-4-mini-instruct for ticket labels. The app calls the deployment names through AIProjectClient with a managed identity.
    Why that choice
    Simple work moves to the cheaper model, and a model change becomes a deployment change instead of a code change.
    The result
    Labelling got faster, the large model handled only what needed it, and the next model upgrade was done by repointing a deployment.

    When to use it and when not to

    ✓ Use it when…

    • You need a model reply inside your own app, with your own logic around it.
    • Different tasks need different models, sizes or deployment types.
    • You want keyless access that works on a laptop and in Azure.

    ✕ Think twice when…

    • A prebuilt Foundry Tool already does the job, such as extracting invoice fields.
    • Rules or a lookup table can answer exactly. Don't pay for a model call.
    • You would paste a key into code. Use Microsoft Entra ID.

    ↔ Alternatives to consider

    • Foundry Tools such as Content Understanding for predictable, structured extraction.
    • Foundry Agent Service when the model needs tools, files and memory.
    • Rules or code for exact answers.
    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-103 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

    An application calls a model in a Microsoft Foundry project. The model was deployed with the deployment name support-chat. The application passes model="gpt-4.1-mini" and receives a DeploymentNotFound error.

    What should you change?

    Question 2

    Question 2 of 5

    A company must label 200,000 short support tickets each day as billing, delivery or other. The labels are simple, and cost and latency matter more than deep reasoning.

    Which model should you deploy for this task?

    Question 3

    Question 3 of 5

    A Python application must connect to a Microsoft Foundry project by using the Foundry SDK. Which value does AIProjectClient require?

    Question 4

    Question 4 of 5 · Select 2

    An application runs on Azure Container Apps and calls a Foundry model deployment. Security policy forbids storing API keys.

    Which two actions should you perform? Select two.

    Question 5

    Question 5 of 5

    Customers upload photos of damaged parcels, and the app must describe the damage in text.

    Which type of model should you deploy?

    Interview preparation

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

    Beginner Why does my app pass a deployment name and not a model name?

    Model answer

    The deployment is the thing that exists in your resource. It points to one model, one version, one deployment type and a slice of quota. If the app used the model name, you could never change the model behind it without editing code.

    Intermediate How do you pick between a large model and a small one?

    Model answer

    I start from the task. Hard, multistep or long-document work goes to a large or reasoning model. Simple, high-volume work such as labelling goes to a small model. Then I test both on my own examples, because a small model that passes is much cheaper.

    Experienced developer How should an app authenticate to a Foundry project from Azure?

    Model answer

    With a managed identity and Microsoft Entra ID. I enable the identity on the host, give it a Foundry role such as Foundry User on the resource, and use DefaultAzureCredential, so there is no key in code or configuration.

    Scenario A call fails with DeploymentNotFound but the model is deployed. What do you check?

    Model answer

    I check the model parameter first. It must be the deployment name I chose, which might be support-chat, not gpt-4.1-mini. Then I check the endpoint is for the right project and the deployment is in that resource.

    Quick revision

    Key points

    • A deployment holds the model, version, deployment type and capacity.
    • Apps pass the deployment name in the model parameter.
    • The project endpoint plus DefaultAzureCredential gives keyless access.
    • Use small models for simple volume work and large or reasoning models for hard work.
    • Multimodal models accept images or audio as input.

    Important terminology

    Deployment
    A named copy of a model in a Foundry resource, with a version, a deployment type and a capacity. Apps call it by name.
    Project endpoint
    The URL an app uses to reach one Foundry project, shaped like https://<resource>.services.ai.azure.com/api/projects/<project>.
    Small language model (SLM)
    A compact model such as Phi-4-mini-instruct that is cheap and fast for simple, high-volume tasks.
    Multimodal model
    A model that accepts more than text, such as images or audio, as input.
    DefaultAzureCredential
    An Azure Identity credential that tries your sign-in locally and a managed identity in Azure, so code needs no key.
    Responses API
    The OpenAI-compatible API your app calls with the deployment name and an input to get a reply and token usage.

    Common mistakes

    • Passing the model name instead of the deployment name.
    • Sending every request to the largest model.
    • Pasting an API key into code when Entra ID works.

    Exam tips

    • "Cheapest model for simple, high-volume labelling" = small language model.
    • "404 DeploymentNotFound" = the app used a model name, not the deployment name.
    • "No secrets in code" = managed identity + DefaultAzureCredential.

    Five quick revision questions

    1. 1.What does the app pass in the model parameter?Show

      The deployment name.

    2. 2.What does AIProjectClient need?Show

      The project endpoint and a credential.

    3. 3.Which model type reads photos?Show

      A multimodal model.

    4. 4.Which model suits cheap simple labelling?Show

      A small language model.

    5. 5.Which credential avoids keys?Show

      DefaultAzureCredential.

    Official references

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

    Next up: Retrieval-Augmented Generation (RAG) in an App

    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.