Connecting Your App to Foundry
Every AI-powered application starts with a connection to Microsoft Foundry. Learn how to configure your app, deploy models, and use the Foundry SDKs and connectors to integrate generative AI into your code.
Your first connection to Foundry
Connecting your app to Foundry is like plugging in a power cable — until you do it, nothing works.
You need three things: (1) a Foundry Project (your workspace), (2) a deployed model (what you’re calling), and (3) the right SDK in your code (how you call it). Once connected, your Python app can send prompts and get AI-powered responses in a few lines of code.
The connection stack
New here? Throughout this course, you’ll follow four teams: 🏥 NeuralMed (health-tech startup), 🏦 Atlas Financial (enterprise bank), 🚀 MediaForge (content operations platform), and 👨💻 Kai (AI engineer at a logistics company). They’re introduced in Module 1.
| Layer | What You Configure | Example |
|---|---|---|
| Authentication | How your app proves its identity | Managed identity or DefaultAzureCredential |
| Endpoint | Your Foundry project’s URL | https://your-project.services.ai.azure.com |
| Deployment name | Which model deployment to call | ”gpt4o-prod” |
| SDK | Client library in your code | azure-ai-projects, openai |
Two SDK options
| Feature | azure-ai-projects SDK | OpenAI Python SDK |
|---|---|---|
| What it is | Microsoft's unified Foundry SDK | OpenAI's official Python library (Azure-compatible) |
| Best for | Full Foundry integration (agents, eval, tools, search) | Simple chat/completion — OpenAI-compatible endpoints |
| Agent support | Yes — full Agent Service management, Foundry IQ, evaluation | Supports Responses API and function calling, but no Foundry-specific features (evaluation, Foundry IQ, Agent Service management) |
| Evaluation | Built-in evaluator access | Not included |
| Install | pip install azure-ai-projects | pip install openai |
Exam tip: Which SDK to recommend
The exam may ask which SDK to use. Decision rule:
- Building agents, using evaluation, or integrating Foundry Tools? →
azure-ai-projects - Simple chat completion from a deployed model? → Either works, but OpenAI SDK is simpler
- Migrating from OpenAI to Azure? → OpenAI SDK with Azure endpoint (minimal code changes)
Connecting with Python — the pattern
The typical connection pattern uses DefaultAzureCredential for keyless auth:
| Step | What Happens |
|---|---|
| 1. Import SDK | Import the Foundry client and credential classes |
| 2. Create credential | DefaultAzureCredential() — tries managed identity first, then Azure CLI, then other methods |
| 3. Create client | Pass endpoint URL and credential to the SDK client |
| 4. Call the model | Send messages using the deployment name |
| 5. Process response | Read the model’s response from the returned object |
Real-world example: Kai's first Foundry connection
Kai connects the logistics platform to Foundry:
- Creates a Foundry Project in East US 2 via the portal
- Deploys GPT-4o with deployment name “route-assistant”
- Enables managed identity on the Azure Container App hosting the code
- Grants “Azure AI User” role to the Container App’s identity
- Writes Python code using
azure-ai-projectsSDK withDefaultAzureCredential - Tests locally using Azure CLI credentials (same
DefaultAzureCredentialfalls back to CLI)
The same code works locally (uses CLI auth) and in production (uses managed identity) — no code changes needed.
Model consumption patterns
Once connected, you consume models in different patterns:
| Pattern | Use Case | How It Works |
|---|---|---|
| Chat completion | Conversational AI, Q&A | Send message history, get response |
| Single completion | One-shot generation (summaries, translations) | Send one prompt, get one response |
| Streaming | Real-time chat UX | Receive response token-by-token as generated |
| Batch | Bulk processing (10,000 emails) | Submit batch job, retrieve results later |
| Function calling | Agent tools | Model requests function execution, you return results |
Key terms
Knowledge check
Kai's logistics app runs on Azure Container Apps and needs to call a GPT-4o deployment in Foundry. The security team requires no API keys in code. How should Kai authenticate?
MediaForge is building a content generation platform that needs agents with tools, evaluation tracking, and Foundry IQ integration. Which SDK should they use?
🎬 Video coming soon