|
| 1 | +Microsoft Foundry provides a unified approach for building AI applications by connecting to a single project endpoint. The Microsoft Foundry SDK enables developers to work with resources in a Foundry project through language-specific client libraries, making it easier to build AI apps that leverage models, connections, and other resources. |
| 2 | + |
| 3 | +## Understanding the Microsoft Foundry SDK |
| 4 | + |
| 5 | +The Microsoft Foundry SDK provides programmatic access to resources in your projects through a REST API and language-specific client libraries. Available SDKs include: |
| 6 | + |
| 7 | +- [Azure AI Projects for Python](https://pypi.org/project/azure-ai-projects?azure-portal=true) |
| 8 | +- [Azure AI Projects for Microsoft .NET](https://www.nuget.org/packages/Azure.AI.Projects?azure-portal=true) |
| 9 | +- [Azure AI Projects for JavaScript](https://www.npmjs.com/package/@azure/ai-projects?azure-portal=true) |
| 10 | + |
| 11 | +> [!NOTE] |
| 12 | +> This module uses Python code examples for common tasks. You can refer to the language-specific SDK documentation for equivalent code in your preferred language. Each SDK is developed and maintained independently, so some functionality may be at different stages of implementation. |
| 13 | +
|
| 14 | +## Installing the SDK |
| 15 | + |
| 16 | +To use the Azure AI Projects library in Python, install the **azure-ai-projects** package from PyPI along with supporting packages: |
| 17 | + |
| 18 | +```bash |
| 19 | +pip install azure-ai-projects azure-identity openai |
| 20 | +``` |
| 21 | + |
| 22 | +## Two client types |
| 23 | + |
| 24 | +The Microsoft Foundry SDK exposes two distinct client types to support different operations: |
| 25 | + |
| 26 | +### Project client |
| 27 | + |
| 28 | +The **project client** (`AIProjectClient`) provides access to Foundry-native operations that don't have OpenAI equivalents. Use the project client to: |
| 29 | + |
| 30 | +- List and retrieve resource connections |
| 31 | +- Access project properties and configuration |
| 32 | +- Enable application tracing |
| 33 | +- Manage datasets and indexes |
| 34 | + |
| 35 | +### OpenAI-compatible client |
| 36 | + |
| 37 | +The **OpenAI-compatible client** handles operations that build on OpenAI concepts and patterns. Use this client for: |
| 38 | + |
| 39 | +- Generating responses with the Responses API |
| 40 | +- Working with agents |
| 41 | +- Running evaluations |
| 42 | +- Fine-tuning models |
| 43 | +- Accessing Foundry direct models (non-Azure-OpenAI models) |
| 44 | + |
| 45 | +Most applications use both clients: the project client for setup and configuration, and the OpenAI-compatible client for generating AI responses. |
| 46 | + |
| 47 | +## Connecting to a project |
| 48 | + |
| 49 | +Each Foundry project has a unique endpoint that you can find on the project's **Overview** page in the Foundry portal at [https://ai.azure.com](https://ai.azure.com?azure-portal=true). |
| 50 | + |
| 51 | +The project endpoint follows this format: |
| 52 | + |
| 53 | +``` |
| 54 | +https://<resource-name>.services.ai.azure.com/api/projects/<project-name> |
| 55 | +``` |
| 56 | + |
| 57 | +Use this endpoint to create an **AIProjectClient** object: |
| 58 | + |
| 59 | +```python |
| 60 | +from azure.identity import DefaultAzureCredential |
| 61 | +from azure.ai.projects import AIProjectClient |
| 62 | + |
| 63 | +project_endpoint = "https://<resource-name>.services.ai.azure.com/api/projects/<project-name>" |
| 64 | +project_client = AIProjectClient( |
| 65 | + credential=DefaultAzureCredential(), |
| 66 | + endpoint=project_endpoint |
| 67 | +) |
| 68 | +``` |
| 69 | + |
| 70 | +> [!NOTE] |
| 71 | +> The code uses default Azure credentials to authenticate. To enable this authentication, you need to install the **azure-identity** package (shown in the installation command earlier). |
| 72 | +
|
| 73 | +> [!TIP] |
| 74 | +> To access the project successfully, the code must run in an authenticated Azure session. For example, you can use the Azure CLI `az login` command to sign in before running the code. |
| 75 | +
|
| 76 | +## Getting an OpenAI-compatible client |
| 77 | + |
| 78 | +Once you have a project client, you can retrieve an OpenAI-compatible client to work with models and generate responses: |
| 79 | + |
| 80 | +```python |
| 81 | +from azure.identity import DefaultAzureCredential |
| 82 | +from azure.ai.projects import AIProjectClient |
| 83 | + |
| 84 | +# Connect to the project |
| 85 | +project_endpoint = "https://<resource-name>.services.ai.azure.com/api/projects/<project-name>" |
| 86 | +project_client = AIProjectClient( |
| 87 | + credential=DefaultAzureCredential(), |
| 88 | + endpoint=project_endpoint |
| 89 | +) |
| 90 | + |
| 91 | +# Get an OpenAI-compatible client |
| 92 | +openai_client = project_client.get_openai_client(api_version="2024-10-21") |
| 93 | +``` |
| 94 | + |
| 95 | +The OpenAI-compatible client provides access to the Responses API and other OpenAI-style operations, which you'll learn about in subsequent units. |
0 commit comments