LoopAI-103

Before you start

Short explainers for ideas this lesson builds on. Watch these first if they're new to you.

0 of 1 watched · about 2 min

Go deeper

Unlocks when you've watched the lesson.

0 of 1 watched · about 2 min
Read this lesson

Four decisions

Microsoft Foundry gives you flexibility when you build a chat app, so before you start, it's worth knowing your options and how to choose. There are four considerations. Endpoints: for chat apps, each Foundry project gives you two main front doors, a project endpoint and an Azure OpenAI endpoint, and your client app walks through one of them to reach things like model deployments. The client SDK: the door you pick decides the library, either the Microsoft Foundry SDK or the OpenAI SDK. Both give you an OpenAI-compatible client that sends prompts to models, but their features differ. Authentication: production apps should sign in with Microsoft Entra ID, as their own identity, and get short-lived tokens; for quick tests, the Azure OpenAI endpoint also accepts an API key. And the chat API: ChatCompletions or Responses. Responses is recommended for most new projects, while ChatCompletions is well established and works across many models and platforms. This unit covers endpoints, SDKs, and authentication. The chat APIs come next.

The project endpoint

The Foundry SDK gives you programmatic access to your project, through a REST API and client libraries: Azure AI Projects for Python, for dot NET, and for JavaScript. This module uses Python; each language's SDK is maintained separately, so features can be at different stages. Install the azure AI projects package, plus azure identity, and the OpenAI package too, because the Foundry SDK's chat client is derived from the OpenAI SDK. Copy the project endpoint from your project's Overview page in the Foundry portal. Pass it to an AI Project Client, with a default Azure credential. Your code needs a signed-in Azure session to run, for instance after you run az login. The project client handles Foundry-native operations that have no OpenAI equivalent: retrieving connections, accessing project configuration, enabling tracing, and managing datasets and indexes. To chat with a model, call its get OpenAI client method, and use the client it returns.

The Azure OpenAI endpoint

The OpenAI SDK is the official library for calling the OpenAI API. Behind the scenes it takes care of the HTTP calls, signing in, retries, and reading the replies, and it behaves the same whether a model is hosted by OpenAI, deployed in Azure OpenAI, or served from Foundry. Install the openai package, and azure identity if you'll authenticate with Entra ID tokens. Your Azure OpenAI endpoint is also on the Overview page, and ends in slash openai slash v1. Create an OpenAI client with that base URL, and a bearer token provider from your default Azure credential. Entra ID is recommended, but you can also use an API key: keep it in Azure Key Vault, and never put it in your code. Or put the address and the key in two environment variables, open AI base URL and open AIAPI key, and the client finds them on its own. However you set it up, this one client covers the Responses API, chat completions, image generation, and Foundry direct models. And if you need a specific Azure OpenAI API version, you can create an AzureOpenAI client instead, with an Azure endpoint, a key, and an API version.

Which SDK, when

So which SDK should you choose? Use the Foundry SDK when your app needs Foundry-specific capabilities: the Foundry Agent Service, tool invocation and approval workflows, cloud evaluations, tracing and observability, Foundry direct models, and project metadata, connections, and governance. Microsoft recommends it for apps with agents, evaluations, or other Foundry features. Use the OpenAI SDK when you want maximum OpenAI compatibility: existing code and tools, portability between OpenAI and Azure OpenAI, the Chat Completions, Responses, and Images APIs, and minimal dependence on Foundry concepts. It's ideal for model inference, but it doesn't give you agents or evaluations. Both work with the same Foundry project, and plenty of apps use them side by side: Foundry's SDK looks after the project, while the OpenAI SDK does the talking to models.

Facts from Microsoft's documentation: Get started with Microsoft Foundry SDKs and endpoints; Endpoints for Microsoft Foundry Models (CC BY 4.0), rewritten in Loop's own words and examples. Narration, animation, and quiz by Loop. The coding lab is based on code samples in Microsoft's Azure AI documentation (MicrosoftDocs/azure-ai-docs, MIT License; notice). Microsoft, Azure, and Microsoft Foundry are trademarks of Microsoft. Loop is independent and not affiliated with or endorsed by Microsoft.