Foundry SDKs and Connectors
30-second answer
The Foundry SDK (azure-ai-projects) opens a project with AIProjectClient, using the project endpoint and DefaultAzureCredential. From it you get an OpenAI-compatible client, the project's deployments, agents and connections. A connection stores the target and authentication of another resource, such as Azure AI Search or Application Insights, so your code reads it by name instead of holding a URL or a key.
Exam objective: 2.1.5 Integrate generative workflows into applications by using Foundry SDKs and connectors. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
The project <strong>Overview</strong> shows the <strong>project endpoint</strong>. That one URL is what <code>AIProjectClient</code> needs.
👆 Click the glowing item in the portal to continue
Read the steps as text
- The project Overview shows the project endpoint. That one URL is what AIProjectClient needs.
- Keep the endpoint in an environment variable and sign in with DefaultAzureCredential. Your own sign-in works on your laptop; a managed identity works in Azure.
- A connection stores a target and how to authenticate to it. The app reads it with project.connections.get("search-contoso") instead of holding the URL or a key.
- Connecting Application Insights lets the SDK find where traces should go. Later lessons use it.
🧪 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
SDK, project endpoint and connections
The Foundry SDK (azure-ai-projects) opens one door: AIProjectClient with the project endpoint and DefaultAzureCredential. From it your app gets an OpenAI-compatible client, deployments and connections (Azure AI Search, Application Insights) with no secrets in code.
🤔 What happens if…
Read this tour as text
- Deploy a model, call the deployment. A deployment is a named copy of a model with a version, a deployment type and capacity. Your app calls the deployment name, never the model name. Pick a large model for hard work and a small language model for cheap, fast, simple work.
- RAG: retrieve first, then answer. Retrieval-augmented generation searches your own content (Azure AI Search, hybrid keyword plus vector), puts the best chunks in the prompt and asks the model to answer from them with citations. Without retrieval the model guesses.
- A multistep flow with checks. A workflow breaks one big request into steps you control: classify, extract to a JSON schema, call a tool, draft, then verify. Retries, fallbacks and a final check live in code, so one bad step can’t slip through unseen.
- Evaluate before you ship. Evaluators score each answer on a test set: groundedness (is it supported by the context?), relevance, coherence and safety checks. A fabrication shows up as a low groundedness score on one row, so you fix it before users see it.
- SDK, project endpoint and connections. The Foundry SDK (
azure-ai-projects) opens one door: AIProjectClient with the project endpoint and DefaultAzureCredential. From it your app gets an OpenAI-compatible client, deployments and connections (Azure AI Search, Application Insights) with no secrets in code. - Design the agent: role, goal, tool schema. An agent is a model plus instructions (role and goal), tools and a conversation (thread). A strict function schema names each parameter and marks the required ones, so the model asks the user instead of inventing a value.
- Retrieval, function calling and memory. One agent can use file search for documents, a function for live data and memory for what it learned about a user. The model asks to call a function; your code runs it and returns the result. Memory survives into a new conversation.
- Multi-agent orchestration. Several specialist agents can share a job. Sequential passes work down a line, concurrent fans out and merges, handoff moves control to the right specialist, group chat lets agents take turns in one shared conversation and Magentic lets a manager agent plan and delegate. Microsoft Agent Framework builds all five.
- Autonomy with approvals. Reads are safe, writes are not. A tool marked approval required pauses the run until a person decides. A hard limit in code blocks what no one should approve, whatever the model says.
- Monitor and debug agent runs. Agent evaluators read the whole run: intent resolution, tool call accuracy and task adherence. Error analysis groups the failing rows, such as a made-up tool argument, and points to the fix.
- Tune prompts and parameters. Instructions shape tone and rules, a few-shot example shows the format, temperature and top_p change how adventurous the wording is, and max output tokens caps length. A self-critique loop drafts, checks against a checklist and revises once.
- Trace every call and count tokens. OpenTelemetry spans record each agent run, model call and tool call, with tokens and latency, and Application Insights stores them. Tracing is opt-in, and recording message content is for development only because it captures prompts and answers.
- Route requests to the right model. A hybrid design puts rules first for answers code can decide, a small model for easy language work and a large or reasoning model only when needed. A model router can pick for you. Fewer big-model calls means a lower bill and faster replies.
Contoso Retail wants one app that sends hard questions to a large model and simple ones to a small one. Deploy both, find the project endpoint, call each deployment keylessly, and see what happens when the app passes a model name instead of a deployment name.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
An API key and a search URL were pasted into the repo, and every environment needs a code change.
😊 THE SOLUTION
Use the project endpoint, Entra ID sign-in and connections.
- Keys in code✓ DefaultAzureCredential
- URLs copied per environment✓ Project connections
- Different clients for each service✓ AIProjectClient with the OpenAI-compatible client
Start with a question
Why does a hotel give you a key card instead of the master key?
A key card opens your room and nothing else, and the front desk can cancel it. A master key opens everything and, if it’s lost, every lock is at risk.
An API key pasted in code is the master key. Microsoft Entra ID with a managed identity is the key card: the app proves who it is, gets a short-lived token, and only the rooms its role allows. The Foundry SDK is built around that.
Explain it like I’m 10
The technical explanation
One client, many doors
# 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"], # .../api/projects/<project>
credential=DefaultAzureCredential())
openai = project.get_openai_client() # model calls with deployment names
for d in project.deployments.list(): # what is deployed
print(d.name, d.model_name)
for c in project.connections.list(): # what the project can reach
print(c.name, c.type, c.target)
| You want | Use |
|---|---|
| Call a model | project.get_openai_client() then responses.create(model=<deployment>) |
| List deployments | project.deployments.list() |
| Reach another resource | project.connections.get("search-contoso") |
| Create and run agents | project.agents and the agent client |
| Find the trace destination | The project’s telemetry helpers (Application Insights connection string) |
The package also exists for JavaScript, .NET and Java, and the same operations are available over REST, as of 25 November 2026.
Connections keep secrets out of code
Create a connection in the portal (Settings > Connected resources) or with the CLI. A connection has a category (for example Azure AI Search or Application Insights), a target and an authentication type. Prefer Microsoft Entra ID. Then grant the right role: the project’s managed identity needs Search Index Data Reader on the search service, for example.
az cognitiveservices account project connection create -n contoso-agents -g rg-agents \
--project-name order-desk --connection-name search-contoso --file search-connection.yml
conn = project.connections.get("search-contoso") # name in, target out
print(conn.target) # https://srch-contoso-agents.search.windows.net
Two endpoints, don’t mix them
The project endpoint (.../api/projects/<project>) is for AIProjectClient. The resource endpoint (https://<resource>.services.ai.azure.com/) is what Foundry Tools and some evaluator settings expect. When a call can’t find anything, check you used the right one.
Architect level Local development to production
Locally, DefaultAzureCredential can use your Azure CLI or Visual Studio Code sign-in. In Azure it uses the managed identity assigned to the host. Give each environment its own project and its own endpoint in an environment variable, and keep the identity roles in your infrastructure code. The application code then stays identical from laptop to production.
Real-world business scenario
Northwind Traders (fictional)
- The problem
- Search URLs and an API key were copied into five services. A key leaked in a public repository, and every environment needed code edits.
- What they used
- One Foundry project per environment, a connection called search-contoso with Entra ID authentication, a managed identity per service with Search Index Data Reader, and code that reads the connection through AIProjectClient.
- Why that choice
- No key remains to leak, the same code runs in every environment, and rotating or moving the search service means editing one connection.
- The result
- The leaked key was revoked with no outage, and new services connected by name in minutes.
When to use it and when not to
✓ Use it when…
- Your app calls Foundry models, agents or evaluations from code.
- Several services need the same search or monitoring resource.
- You want the same code on a laptop and in Azure.
✕ Think twice when…
- You would store a key in code or a config file.
- A single no-code playground test is enough.
- You need a service the project has no connection or tool for. Call it directly with its own SDK.
↔ Alternatives to consider
- The OpenAI SDK directly against the resource endpoint for model calls only.
- Microsoft Agent Framework for code-first multi-agent apps.
- REST calls when no SDK fits.
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.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What is a connection in Foundry?
Model answer
It is a saved link from the project to another resource, like Azure AI Search, with its address and how to sign in. The app asks the project for it by name, so the address and the secret stay out of the code.
Intermediate How does the same code run on a laptop and in Azure?
Model answer
I create the client with DefaultAzureCredential. On the laptop it uses my signed-in account. In Azure it uses the managed identity of the host. The code doesn't change and holds no key.
Experienced developer What do you do when the SDK call returns 403?
Model answer
I check the role assignment for the identity on the Foundry resource and, for a connection, on the target resource too. For example the project identity needs Search Index Data Reader on the search service. Then I confirm the endpoint is for the right project.
Scenario A teammate pasted a key into code to reach Azure AI Search. What do you change?
Model answer
I create a project connection to the search service with Microsoft Entra ID authentication, assign the right role, and change the code to read the connection by name and sign in with DefaultAzureCredential. Then I rotate the key that leaked.
Quick revision
Key points
- AIProjectClient takes the project endpoint and a credential.
- get_openai_client() returns the client for model calls.
- Connections hold targets and authentication for other resources.
- DefaultAzureCredential keeps the same code across environments.
- Give the identity the roles it needs on every resource it touches.
Important terminology
- AIProjectClient
- The main class in azure-ai-projects. It connects to one Foundry project through its endpoint.
- Connection
- A project setting that stores the target and authentication method of another resource, such as Azure AI Search.
- Project endpoint
- The URL for one project, used to create the client.
- Managed identity
- An Azure-managed identity that an app uses to get Microsoft Entra ID tokens without a stored secret.
- OpenAI-compatible client
- A client from get_openai_client() that you call with the OpenAI Responses API shape, using deployment names.
- Connector
- Informal word for a way to reach another service from a project, such as a connection or a tool.
Common mistakes
- Hard-coding service URLs and keys.
- Forgetting the role assignment, then blaming the SDK for a 403.
- Mixing up the resource endpoint and the project endpoint.
Exam tips
- "Read the Azure AI Search endpoint without hard-coding it" = project.connections.get(name).
- "Same code on a laptop and in Azure with no key" = DefaultAzureCredential.
- "Package that contains AIProjectClient" = azure-ai-projects.
Five quick revision questions
-
1.Which package has AIProjectClient?Show
azure-ai-projects.
-
2.What does project.get_openai_client() return?Show
An OpenAI-compatible client.
-
3.What does a connection store?Show
A target and its authentication method.
-
4.Which credential keeps code key-free?Show
DefaultAzureCredential.
-
5.Which value creates the client?Show
The project endpoint.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Design an Agent: Role, Goals, Threads and Tool Schemas
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.