Connecting Applications to a Foundry Project
This lesson explains the connection pattern used throughout the course: finding a project's endpoint, authenticating and obtaining clients for models and agents.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the endpoint forms a Foundry resource exposes.
- Connect to a project with the Foundry SDK.
- Keep endpoints and deployment names in configuration.
- Diagnose 401, 403 and 404 connection errors.
Endpoints
An endpoint is the base URL to which an application sends its requests. Every client, whether an SDK or a plain HTTP call, needs the endpoint and a credential before it can do anything. A Foundry resource exposes three endpoint forms on its custom subdomain, and each serves a different set of APIs.
The project endpoint, https://<resource>.services.ai.azure.com/api/projects/<project>, is used by the Foundry SDK for agents, evaluations, connections and the project's OpenAI-compatible API.
The Azure OpenAI v1 endpoint, https://<resource>.openai.azure.com/openai/v1/, serves OpenAI-compatible APIs for models, embeddings, images, audio and video.
The Foundry Tools endpoint, https://<resource>.cognitiveservices.azure.com/, serves Language, Translator, Content Understanding and other tools.
All three endpoints belong to the same resource and accept the same Microsoft Entra ID credentials, so the choice depends on what the code is doing. Code that works with project items, such as agents, evaluations, datasets or connections, uses the project endpoint through the Foundry SDK. Code that only calls a model, for example an existing application written against the OpenAI library, can use the v1 endpoint with a token provider. Code that calls a Foundry Tool, such as Translator document translation or a Content Understanding analyzer, uses the tools endpoint and that tool's own SDK or REST API. Mixing them up is a common cause of 404 errors, because each endpoint exposes only its own paths.
The following diagram shows which client uses which endpoint, and what each endpoint serves.

The following screenshot shows the project's home page in the Foundry portal, which displays the project endpoint and the resource's Azure OpenAI endpoint.

services.ai.azure.com/api/projects/<project>; the API key is hidden, because keyless authentication is preferred.Which endpoint?
The Foundry SDK
In Python, azure-ai-projects version 2.x targets the current Foundry API (version 1.x targets the classic API and is not compatible). The application installs it with azure-identity and creates an AIProjectClient. get_openai_client() returns an authenticated OpenAI client for the Responses API, conversations and agent calls.
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
project = AIProjectClient(
endpoint=os.environ["PROJECT_ENDPOINT"], # https://<resource>.services.ai.azure.com/api/projects/<project>
credential=DefaultAzureCredential(),
)
openai = project.get_openai_client()
response = openai.responses.create(
model="chat-primary", # deployment name
input="Summarize our return policy in two sentences.",
)
print(response.output_text)The project client also exposes project.agents for agent versions, project.connections for connected resources, project.deployments to list model deployments, datasets and indexes, evaluation operations and project.telemetry to obtain the Application Insights connection string for tracing.
Configuration and connections
Endpoints and deployment names are configuration, not code: environment variables, Azure App Configuration or application settings. The application identity needs a data plane role such as Foundry User. Project connections record how the project reaches other resources, such as Azure AI Search, Storage, Application Insights or Grounding with Bing Search, and are referenced by agent tools. Connections should use Microsoft Entra ID; when a key is unavoidable, it is stored in the connection, not distributed to each application.
Troubleshooting connections
Most connection failures fall into a few categories, and the error code points to the cause. A 401 error means authentication failed: DefaultAzureCredential found no usable credential, or a token was requested for the wrong tenant. A 403 error means the identity authenticated but lacks a data plane role, such as Foundry User, on the resource or project; new role assignments can take several minutes to take effect. A 403 error can also come from network rules when public network access is disabled and the caller is outside the allowed network.
A 404 error usually means a wrong endpoint form, for example a Foundry Tools endpoint used where the project endpoint is required, or a deployment name that does not exist. Applications refer to the deployment name, which the team chose when deploying, not the model name. Listing the project's deployments with the SDK confirms the names available.
Decode the connection error
A failing deployment
A Python app works on a developer's laptop but fails with a 401 error after deployment to Azure Container Apps. The code uses DefaultAzureCredential and reads the project endpoint from an environment variable.
Locally, DefaultAzureCredential used the developer's Azure CLI sign-in, which has the Foundry User role. In Container Apps, it uses the app's managed identity, which either is not enabled or has no role. Enable a managed identity (setting AZURE_CLIENT_ID if it is user-assigned) and assign it Foundry User on the project. Adding an API key would contradict keyless design.
An application works locally but gets 401 errors in Azure. What is the likely cause?
Show answer
The application's managed identity is missing or has no role on the Foundry resource, while locally the developer's own sign-in has access.
Exam Tips
Remember for the exam
- Project endpoint: services.ai.azure.com/api/projects/<project>; use azure-ai-projects 2.x.
- get_openai_client() returns an authenticated client for Responses, conversations and agents.
- 401 in Azure but not locally: the managed identity is missing or lacks a role.