Develop an AI app with the Microsoft Foundry SDK
Microsoft Foundry provides a REST API to work with:
-
AI Foundry projects
-
Resources inside those projects
-
-
It also offers language-specific SDKs to make coding easier.
-
Using the SDK, developers can:
-
Connect to a Foundry project
-
Access project resources and models
-
Perform AI operations (e.g., send prompts to generative AI models and process responses)
-
Core SDK Library
-
The main library is Azure AI Projects
-
It allows you to:
-
Connect to a Microsoft Foundry project
-
Access all resources defined in the project
-
Available SDKs:
-
Azure AI Projects for Python
-
Azure AI Projects for .NET
-
Azure AI Projects for JavaScript
Each SDK is developed independently, so features may differ slightly across languages.
Language Used in This Module
-
This module uses Python examples
-
Equivalent examples are available in other SDK documentation
- pip install azure-ai-projects
Connecting to a Microsoft Foundry Project
Project Endpoint
-
Each project has a unique endpoint
-
You can find it on the Project Overview page in the Microsoft Foundry portal
Types of Endpoints in a Project:
-
Project endpoint
-
Access project connections, agents, and models
-
-
Azure OpenAI Service endpoint
-
Use OpenAI models
-
-
Foundry Tools endpoint
-
Use tools like Azure Vision and Azure Language
-
- Use the project endpoint to create a project client
Authentication
-
Uses DefaultAzureCredential
-
You must install the identity package:
pip install azure-identity
Important Authentication Requirement
-
Code must run in an authenticated Azure session
-
Example:
-
Run
az loginusing Azure CLI before executing the code
-
Summary
-
Microsoft Foundry SDK lets developers programmatically work with AI projects
-
Azure AI Projects is the core library
-
Authentication and the correct project endpoint are mandatory
Project Connections
-
Every Microsoft Foundry project includes connected resources
-
These resources are defined at:
-
Parent level (Microsoft Foundry resource / hub)
-
Project level
-
-
Each connection links to an external service, such as:
-
Azure Storage
-
Azure AI Search
-
Azure OpenAI
-
Another Microsoft Foundry resource
-
Why Project Connections Matter
-
Connections allow your project to use external services
-
Using the Microsoft Foundry SDK, you can:
-
Connect to a project
-
Retrieve its connections
-
Use those connections to consume services programmatically
-
Accessing Connections Using the SDK
-
In Python, the
AIProjectClientobject has a connections property -
This property lets you list and retrieve resource connections
Important Connection Methods
connections.list()
-
Returns all connection objects in the project
-
Each object represents one connected resource
-
You can filter results using:
-
connection_typeparameter -
Example:
ConnectionType.AZURE_OPEN_AI
-
connections.get(connection_name, include_credentials)
-
Returns a specific connection by name
-
include_credentials:-
Default:
True -
If
True, credentials are included (e.g., API keys for Foundry Tools)
-
What Connection Objects Contain
-
Connection name
-
Connection type
-
Connection-specific properties
-
Credentials (if included)
-
These details are used to connect to the external resource
Python Example: List All Project Connections
Summary
-
Project connections link Foundry projects to external Azure services
-
Connections can be accessed using
AIProjectClient.connections -
You can:
-
List all connections
-
Get a specific connection
-
Retrieve credentials if needed
-
Purpose
-
A common AI app scenario is to:
-
Connect to a generative AI model
-
Use prompts to have a chat-based conversation
-
Two Ways to Connect to Models
-
Directly using Azure OpenAI SDK
-
Authentication via:
-
API keys
-
Microsoft Entra ID
-
-
-
Using Microsoft Foundry SDK (Recommended for Foundry projects)
-
Retrieve a project client
-
From it, get an authenticated OpenAI chat client
-
Works for any model deployed in the project
-
Why Use Microsoft Foundry SDK?
-
Simplifies consuming models deployed in your project
-
Easy to switch between models
-
Just change the model deployment name
-
-
Automatically handles authentication
Important Tip
-
The OpenAI chat client from Microsoft Foundry can chat with:
-
Azure OpenAI models
-
Non-OpenAI models (e.g., Microsoft Phi models)
as long as they are deployed in the Foundry resource
-
Required Python Packages
Steps to Create a Chat Client
-
Authenticate using
DefaultAzureCredential -
Connect to the Microsoft Foundry project
-
Get an OpenAI chat client using
get_openai_client() -
Send a prompt and receive a chat completion
Python Example: Create a Chat Client
Key Components
-
project_endpoint → Foundry project endpoint
-
get_openai_client() → Returns authenticated chat client
-
model → Deployment name of the model in Foundry
-
messages → Conversation history (system + user roles)
Summary
-
Microsoft Foundry SDK provides an easy way to chat with deployed models
-
Supports multiple models, including non-OpenAI models
-
Authentication is handled using Azure credentials
-
Ideal for building chat-based generative AI apps
Comments
Post a Comment