Chat client apps with the Foundry SDK: AI-901 study notes and practice questions
What to know about Chat client apps with the Foundry SDK for the AI-901 exam, from the Implement AI solutions by using Microsoft Foundry domain (58% of the exam guide), then 4 free questions to test it. Part of the AI-901 study guide.
You do not need to write this code, but you should be able to read it and say what each part does. The current pattern uses the azure-ai-projects 2.x package, which is not compatible with 1.x.
The flow in plain steps
Install azure-ai-projects and azure-identity.
Authenticate with Microsoft Entra ID, using DefaultAzureCredential after az login.
Connect with AIProjectClient(endpoint=..., credential=...). The project endpoint looks like https://<resource-name>.services.ai.azure.com/api/projects/<project-name>.
Get an OpenAI client from the project with project.get_openai_client().
Send a prompt with openai.responses.create(model="<deployment name>", input="...").
Read the answer from response.output_text.
The model value is the name of your deployment, not the catalog name.
Other call styles
Style
Shape
Note
Responses API
responses.create(model=..., input=...)
Current recommended style
Chat Completions
chat.completions.create(model=..., messages=[...]), answer in choices[0].message.content
Still exists; uses a list of system and user messages and accepts temperature and top_p
Multimodal input
input holds text and image items
Lets a model describe or answer questions about an image
Image generation
images.generate(model=..., prompt=..., size=...)
Returns image data you decode and save
How to choose
Which credential? Entra ID with DefaultAzureCredential for the project client. API keys with AzureKeyCredential appear in Language, Speech and Vision samples.
What goes in model? The deployment name.
Where is the reply?output_text for the Responses API.
Common traps
Mixing up client versions. Code written for azure-ai-projects 1.x or hub-based projects will not match the 2.x pattern.
Using the catalog model name instead of the deployment name.
Assuming an API key works everywhere. The agent client requires Entra identity.
Expecting memory from a plain call. Each responses.create call without a conversation is stand-alone.
A university computer science department is writing a Python script that connects to its Foundry project and sends prompts to a chat model. Each developer must sign in with their own Microsoft Entra identity.
Which class connects the script to the Foundry project?
Choose one answer.
AA. TextAnalyticsClient from the azure.ai.textanalytics package, which connects to a Language resource
BB. DefaultAzureCredential from the azure.identity package, which signs in with Microsoft Entra ID
CC. AIProjectClient from the azure.ai.projects package, given the project endpoint and a credential
DD. AzureKeyCredential from the azure.core package, which wraps a resource key
Show the answer and explanation
Answer: C
A. Wrong: TextAnalyticsClient connects to an Azure Language resource for text analysis. It is not the client for a Foundry project, so it cannot send chat prompts to project deployments.
B. Wrong: DefaultAzureCredential provides Microsoft Entra sign-in, and the script passes it to a client. On its own it does not connect the script to any Foundry project.
D. Wrong: AzureKeyCredential wraps a resource key for authentication. It only supplies a key, so it cannot connect the script to a project by itself.
Explanation
AIProjectClient is the class that connects code to a Foundry project, using the project endpoint and a credential. DefaultAzureCredential supplies the Entra sign-in but connects to nothing. The other two classes serve other tasks.
A retail analytics team has started a Python chat app that signs in to its Foundry project with Microsoft Entra ID. The next line should create an OpenAI-style client for sending prompts to a model deployment.
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
project = AIProjectClient(endpoint=ENDPOINT, credential=DefaultAzureCredential())
openai_client = project.________()
Which method name fills the blank?
Choose one answer.
AA. the agents.create_version method
BB. the responses.create method
CC. the get_openai_client method
DD. the create_thread_and_run method
Show the answer and explanation
Answer: C
A. Wrong: agents.create_version creates a versioned agent definition in the project. It does not return a client for sending chat prompts to a model deployment.
B. Wrong: responses.create sends a prompt, but it is a method on the OpenAI-style client, which the blank has to create first.
D. Wrong: create_thread_and_run belongs to the older threads-and-runs pattern, not to the current project client used for chat prompts.
Explanation
The project client gives an OpenAI-style client through get_openai_client, and that client sends prompts with responses.create. Agent definitions and thread-based calls are separate tasks.
A boutique hotel's developer wrote the code below to ask its chat model about spa hours. The model was deployed to the project earlier under a name the developer chose.
openai_client = project.get_openai_client()
response = openai_client.responses.create(
model="spa-hours-chat",
input="What time does the spa open on Sunday?",
)
print(response.output_text)
What must the value of the model argument be?
Choose one answer.
AA. The resource group name that holds the hotel's Foundry resource
BB. The project endpoint URL, which ends with the project's name
CC. The deployment name of the model in the Foundry project
DD. The subscription ID of the Azure account that pays for the model
Show the answer and explanation
Answer: C
A. Wrong: Resource groups organize Azure resources for management and billing. The model argument does not take a resource group name, so this call would fail.
B. Wrong: The project endpoint is the address the client connects to, and it is set on AIProjectClient. The model argument names a deployment, not the endpoint.
C. Right: Correct. In the Foundry SDK, the model argument takes the deployment name you chose when you deployed the model, not a catalog name or version number.
D. Wrong: A subscription ID identifies the Azure account for billing. Passing it as the model argument would not select a deployed model.
Explanation
The model argument of responses.create takes the name of a deployment in the Foundry project. The endpoint, resource group and subscription each identify something else.
A regional clinic network is building an app that calls a Foundry agent. The app runs on developers' laptops during testing and on an Azure virtual machine in production. The security team forbids storing secret keys in source code, configuration files or environment variables.
The agent client requires Microsoft Entra sign-in.
Which authentication approach meets these requirements?
Choose one answer.
AA. A resource key pasted into the client constructor, which the team rotates every quarter
BB. An API key stored in an environment variable and read by AzureKeyCredential
CC. DefaultAzureCredential, which uses az login locally and the VM's managed identity in Azure
DD. Anonymous access, with the agent endpoint left open so that no sign-in is needed
Show the answer and explanation
Answer: C
A. Wrong: A resource key is a shared secret, and the agent client needs a Microsoft Entra identity rather than a key. Pasting the key into code also breaks the security rule.
B. Wrong: An environment variable is still a stored secret, which the security team forbids. Key-based credentials also fail the agent client's Microsoft Entra requirement.
C. Right: Correct. DefaultAzureCredential tries a chain of credentials, using the developer's az login session on a laptop and a managed identity when the app runs on an Azure host with one enabled. No secret is stored, and the agent client gets the Entra sign-in it requires. Learn more: Credential chains in the Azure Identity library for Python (opens in a new tab)
D. Wrong: Removing sign-in would let any caller reach the agent and its tools, which the security team cannot accept. The agent client expects a Microsoft Entra identity, so this option fails both needs.
Explanation
Agent clients in Foundry require Microsoft Entra ID rather than keys. DefaultAzureCredential picks up the developer's az login session during testing and the VM's managed identity in production, so no secret is stored anywhere.
Want more on Chat client apps with the Foundry SDK? The 5 full-length practice sets have 20 more Chat client apps with the Foundry SDK questions, 225 in all, none of them in the free exam. One payment of $9.99 $6.99, no subscription. Get the practice sets →