πŸ”’ Guided

Pre-launch preview. Authorised access only.

Incorrect code

Guided by A Guide to Cloud
Explore AB-900 AI-901
Guided AI-901 Domain 2
Domain 2 β€” Module 3 of 15 20%
14 of 26 overall

AI-901 Study Guide

Domain 1: AI Concepts and Capabilities

  • What is AI? Your First 10 Minutes Free
  • Responsible AI: The Six Principles Free
  • How Generative AI Actually Works Free
  • Choosing the Right AI Model Free
  • Deploying AI Models: Options & Settings
  • AI Workloads at a Glance
  • Text Analysis: Keywords, Entities & Sentiment
  • Speech: Recognition & Synthesis
  • Computer Vision: Seeing the World
  • Image Generation: Creating with AI
  • Information Extraction: From Chaos to Structure

Domain 2: Implement AI Solutions Using Foundry

  • Prompting Fundamentals: System & User Prompts
  • Microsoft Foundry: Your AI Command Center Free
  • Building a Chat App with the Foundry SDK
  • Agents in Foundry: Create & Test
  • Building an Agent Client App
  • Building a Text Analysis App
  • Multimodal: Responding to Speech
  • Azure Speech in Foundry Tools
  • Visual Prompts: Images as Input
  • Generating Images with AI
  • Building a Vision App
  • Content Understanding: Documents & Forms
  • Multimodal Extraction: Images, Audio & Video
  • Building an Extraction App
  • Exam Prep: Putting It All Together

AI-901 Study Guide

Domain 1: AI Concepts and Capabilities

  • What is AI? Your First 10 Minutes Free
  • Responsible AI: The Six Principles Free
  • How Generative AI Actually Works Free
  • Choosing the Right AI Model Free
  • Deploying AI Models: Options & Settings
  • AI Workloads at a Glance
  • Text Analysis: Keywords, Entities & Sentiment
  • Speech: Recognition & Synthesis
  • Computer Vision: Seeing the World
  • Image Generation: Creating with AI
  • Information Extraction: From Chaos to Structure

Domain 2: Implement AI Solutions Using Foundry

  • Prompting Fundamentals: System & User Prompts
  • Microsoft Foundry: Your AI Command Center Free
  • Building a Chat App with the Foundry SDK
  • Agents in Foundry: Create & Test
  • Building an Agent Client App
  • Building a Text Analysis App
  • Multimodal: Responding to Speech
  • Azure Speech in Foundry Tools
  • Visual Prompts: Images as Input
  • Generating Images with AI
  • Building a Vision App
  • Content Understanding: Documents & Forms
  • Multimodal Extraction: Images, Audio & Video
  • Building an Extraction App
  • Exam Prep: Putting It All Together
Domain 2: Implement AI Solutions Using Foundry Premium ⏱ ~16 min read

Building a Chat App with the Foundry SDK

Time to write code. This module shows you how to build a simple chat application using the Microsoft Foundry SDK in Python β€” connecting your code to a deployed AI model.

Your first AI app

β˜• Simple explanation

Building an AI chat app is like sending text messages β€” but to an AI model.

You already know how to test prompts in the Foundry Playground. Now you’re going to do the exact same thing, but from Python code. Your app sends a message to the model, the model sends a response back, and you display it.

Don’t worry if you’re new to coding β€” the exam expects you to understand the code, not write it from scratch. We’ll walk through every line.

The Foundry SDK (azure-ai-projects) provides a Python client library for interacting with deployed models, agents, and tools in Microsoft Foundry. For chat applications, you use the AIProjectClient to connect to your project, then use the OpenAI-compatible API to send and receive messages.

The SDK supports Python, C#, JavaScript/TypeScript (preview), and Java (preview). The AI-901 exam focuses on Python.

The architecture of a chat app

Your Python App  β†’  Foundry SDK  β†’  Foundry Project  β†’  Deployed Model (GPT-4o)
     |                                                          |
     ←────────────────── Response ──────────────────────────────←
ComponentWhat It Does
Your appSends user messages, displays responses
Foundry SDKHandles authentication, API calls, formatting
Foundry projectRoutes the request to the right deployment
Deployed modelGenerates the response

The code: step by step

Step 1: Install the SDK

pip install azure-ai-projects azure-identity

Step 2: Connect to your project

Note: The Foundry SDK is actively evolving. The examples below illustrate the core concepts β€” always check the official SDK documentation for the latest syntax.

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

# Connect to your Foundry project
client = AIProjectClient(
    credential=DefaultAzureCredential(),
    endpoint="https://your-project.services.ai.azure.com"
)

What’s happening:

  • DefaultAzureCredential handles authentication (uses your Azure login)
  • AIProjectClient connects to your specific Foundry project
  • The endpoint is your project’s URL (found in the Foundry portal)

Step 3: Send a message and get a response

# Get an OpenAI-compatible chat client from the project
chat = client.inference.get_chat_completions_client()

# Send a message
response = chat.complete(
    model="gpt4o-coursework",  # Your deployment name
    messages=[
        {"role": "system", "content": "You are a helpful study assistant."},
        {"role": "user", "content": "Explain what a neural network is in simple terms."}
    ],
    temperature=0.7,
    max_tokens=200
)

# Display the response
print(response.choices[0].message.content)

Exam focus: You don’t need to memorise exact SDK method names. Understand the pattern: connect to project β†’ get a client β†’ send messages with roles β†’ read the response.

What’s happening:

  • messages is a list with a system prompt and user message
  • model is the name of your deployment (not the model name β€” your deployment name)
  • temperature and max_tokens control the response behaviour
  • The response comes back in response.choices[0].message.content

Step 4: Build a conversation loop

messages = [
    {"role": "system", "content": "You are a helpful study assistant."}
]

while True:
    user_input = input("You: ")
    if user_input.lower() == "quit":
        break

    messages.append({"role": "user", "content": user_input})

    response = chat.complete(
        model="gpt4o-coursework",
        messages=messages,
        temperature=0.7,
        max_tokens=200
    )

    assistant_message = response.choices[0].message.content
    print(f"AI: {assistant_message}")

    messages.append({"role": "assistant", "content": assistant_message})

Key insight: Each new message includes the full conversation history (messages list). This is how the model maintains context across a conversation.

ℹ️ Why the full conversation is sent every time

AI models are stateless β€” they don’t remember previous conversations. Every API call is independent.

To create the illusion of a conversation, you send the entire chat history with each request:

  1. First call: system + user message
  2. Second call: system + user message 1 + assistant response 1 + user message 2
  3. Third call: system + all previous messages + new user message

This is why token limits matter β€” long conversations eventually exceed the model’s context window.

Exam relevance: Understanding that models are stateless and conversations require full history is a commonly tested concept.

Message roles explained

The three message roles in chat completions
FeaturePurposeWho Creates It
systemSets the AI's role, rules, and behaviour for the entire conversationThe developer (in code)
userThe human's question or instructionThe end user (typed input)
assistantThe AI's previous responses (for conversation history)The model (via API response)

Authentication methods

MethodWhen to Use
DefaultAzureCredentialDevelopment β€” uses your Azure CLI login or managed identity
API keyQuick testing β€” paste the key from the Foundry portal
Managed identityProduction β€” Azure assigns an identity to your app automatically

Exam tip: DefaultAzureCredential is the recommended approach because it works in development (Azure CLI login) and production (managed identity) without code changes.

🎬 Video walkthrough

🎬 Video coming soon

Building a Chat App β€” AI-901 Module 14

Building a Chat App β€” AI-901 Module 14

~16 min

Flashcards

Question

What SDK package do you install to build AI apps with Microsoft Foundry in Python?

Click or press Enter to reveal answer

Answer

azure-ai-projects (and azure-identity for authentication). Install with: pip install azure-ai-projects azure-identity

Click to flip back

Question

Why does a chat app send the full conversation history with every API call?

Click or press Enter to reveal answer

Answer

Because AI models are stateless β€” they don't remember previous messages. To maintain context, you send the complete message history (system + all user/assistant messages) with each request.

Click to flip back

Question

What are the three message roles in a chat completion API call?

Click or press Enter to reveal answer

Answer

system (sets the AI's role and rules), user (the human's question), and assistant (the AI's previous responses, included for conversation history).

Click to flip back

Question

What is DefaultAzureCredential?

Click or press Enter to reveal answer

Answer

A flexible authentication method that automatically detects the best available credential β€” Azure CLI login in development, managed identity in production. Recommended because it works in both environments without code changes.

Click to flip back

Knowledge Check

Knowledge Check

Priya notices that her chat app gives relevant answers in the first few messages but seems to 'forget' context after about 20 exchanges. What is the most likely cause?

Knowledge Check

In a chat completion API call, which message role defines the AI's persistent behaviour rules like 'always respond in French' and 'never discuss politics'?


Next up: Agents in Foundry β€” creating AI that doesn’t just talk, but takes action.

← Previous

Microsoft Foundry: Your AI Command Center

Next β†’

Agents in Foundry: Create & Test

Guided

I learn, I simplify, I share.

A Guide to Cloud YouTube Feedback

© 2026 Sutheesh. All rights reserved.

Guided is an independent study resource and is not affiliated with, endorsed by, or officially connected to Microsoft. Microsoft, Azure, and related trademarks are property of Microsoft Corporation. Always verify information against Microsoft Learn.