- Foundry project
- Hub based project
In this quickstart, you use Azure AI Foundry to:


- Create a project
- Deploy a model
- Run a chat completion
- Create and run an agent
- Upload files to the agent The Azure AI Foundry SDK is available in multiple languages, including Python, Java, JavaScript, and C#. This quickstart provides instructions for each of these languages.
The rest of this article shows how to use a Foundry project. Select hub based project at the top of this article if you want to use a hub based project instead. Which type of project do I need?
Prerequisites
- An Azure subscription. If you don’t have an Azure subscription, create a free account before you begin.
- You must be Owner of the subscription to receive the appropriate access control needed to use your project.
Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
Start with a project and model
- Sign in to the Azure AI Foundry portal.
- On the home page, search and then select the gpt-4o model.

- On the model details page, select Use this model.
- Fill in a name to use for your project and select Create.
- Once your resources are created, you are in the chat playground.
Set up your environment
- Azure AI Foundry project
- Python
- Java (preview)
No installation is necessary to use the Azure AI Foundry portal.
- Install Python and Azure CLI
-
Install these packages:
pip install openai azure-ai-projects azure-identity - Copy the Azure AI Foundry project endpoint in the Overview section of your project. You’ll use it in a moment.

If you don’t see the Azure AI Foundry project endpoint, you’re using a hub based project. (See Types of projects). Switch to a Foundry project, or use the preceding steps to create one.
- Make sure to sign in using the CLI
az login(oraz login --use-device-code) command to authenticate before running your Python scripts.
All the code in this article is at GitHub Quickstart.
- Install Java and Azure CLI.
- Copy the Azure AI Foundry project endpoint in the Overview section of your project. You’ll use it in a moment.

If you don’t see the Azure AI Foundry project endpoint, you’re using a hub based project. (See Types of projects). Switch to a Foundry project, or use the preceding steps to create one.
MODEL_DEPLOYMENT_NAME=gpt-4o
PROJECT_ENDPOINT=https://<your-foundry-resource-name>.services.ai.azure.com/api/projects/<your-foundry-project-name>
- Make sure to sign in using the CLI
az login(oraz login --use-device-code) command to authenticate before running your Java scripts. - Download POM.XML to your Java IDE.
All the code in this article is at GitHub Quickstart.
Run a chat completion
Chat completions are the basic building block of AI applications. Using chat completions you can send a list of messages and get a response from the model.- Azure AI Foundry Portal
- Python
- Java (preview)
- In the chat playground, fill in the prompt and select the Send button.
- The model returns a response in the Response pane.
Substitute your endpoint for the
endpoint in this code:from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
project = AIProjectClient(
endpoint="https://your-foundry-resource-name.ai.azure.com/api/projects/project-name",
credential=DefaultAzureCredential(),
)
models = project.inference.get_azure_openai_client(api_version="2024-10-21")
response = models.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful writing assistant"},
{"role": "user", "content": "Write me a poem about flowers"},
],
)
print(response.choices[0].message.content)
package com.azure.ai.foundry.samples;
import com.azure.ai.inference.ChatCompletionsClient;
import com.azure.ai.inference.ChatCompletionsClientBuilder;
import com.azure.ai.inference.models.ChatCompletions;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.util.logging.ClientLogger;
import com.azure.identity.DefaultAzureCredentialBuilder;
/**
* Sample demonstrating non-streaming chat completion functionality
* using the Azure AI Inference SDK, wired to your AOAI project endpoint.
*
* Environment variables:
* - PROJECT_ENDPOINT: Required. Your Azure AI project endpoint.
* - AZURE_AI_API_KEY: Optional. Your API key (falls back to DefaultAzureCredential).
* - AZURE_MODEL_DEPLOYMENT_NAME: Optional. Model deployment name (default: "phi-4").
* - AZURE_MODEL_API_PATH: Optional. API path segment (default: "deployments").
* - CHAT_PROMPT: Optional. The prompt to send (uses a default if not provided).
*
* SDK Features Demonstrated:
* - Using the Azure AI Inference SDK (com.azure:azure-ai-inference:1.0.0-beta.5)
* - Creating a ChatCompletionsClient with Azure or API key authentication
* - Configuring endpoint paths for different model deployments
* - Using the simplified complete() method for quick completions
* - Accessing response content through strongly-typed objects
* - Implementing proper error handling for service requests
* - Choosing between DefaultAzureCredential and AzureKeyCredential
*
*/
public class ChatCompletionSample {
private static final ClientLogger logger = new ClientLogger(ChatCompletionSample.class);
public static void main(String[] args) {
// 1) Read and validate the project endpoint
String projectEndpoint = System.getenv("PROJECT_ENDPOINT");
if (projectEndpoint == null || projectEndpoint.isBlank()) {
logger.error("PROJECT_ENDPOINT is required but not set");
return;
}
// 2) Optional auth + model settings
String apiKey = System.getenv("AZURE_AI_API_KEY");
String deploymentName = System.getenv("AZURE_MODEL_DEPLOYMENT_NAME");
String apiPath = System.getenv("AZURE_MODEL_API_PATH");
String prompt = System.getenv("CHAT_PROMPT");
if (deploymentName == null || deploymentName.isBlank()) {
deploymentName = "phi-4";
logger.info("No AZURE_MODEL_DEPLOYMENT_NAME provided, using default: {}", deploymentName);
}
if (apiPath == null || apiPath.isBlank()) {
apiPath = "deployments";
logger.info("No AZURE_MODEL_API_PATH provided, using default: {}", apiPath);
}
if (prompt == null || prompt.isBlank()) {
prompt = "What best practices should I follow when asking an AI model to review Java code?";
logger.info("No CHAT_PROMPT provided, using default prompt: {}", prompt);
}
try {
// 3) Build the full inference endpoint URL
String fullEndpoint = projectEndpoint.endsWith("/")
? projectEndpoint
: projectEndpoint + "/";
fullEndpoint += apiPath + "/" + deploymentName;
logger.info("Using inference endpoint: {}", fullEndpoint);
// 4) Create the client with key or token credential :contentReference[oaicite:0]{index=0}
ChatCompletionsClient client;
if (apiKey != null && !apiKey.isBlank()) {
logger.info("Authenticating using API key");
client = new ChatCompletionsClientBuilder()
.credential(new AzureKeyCredential(apiKey))
.endpoint(fullEndpoint)
.buildClient();
} else {
logger.info("Authenticating using DefaultAzureCredential");
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
client = new ChatCompletionsClientBuilder()
.credential(credential)
.endpoint(fullEndpoint)
.buildClient();
}
// 5) Send a simple chat completion request
logger.info("Sending chat completion request with prompt: {}", prompt);
ChatCompletions completions = client.complete(prompt);
// 6) Process the response
String content = completions.getChoice().getMessage().getContent();
logger.info("Received response from model");
System.out.println("\nResponse from AI assistant:\n" + content);
} catch (HttpResponseException e) {
// Handle API errors
int status = e.getResponse().getStatusCode();
logger.error("Service error {}: {}", status, e.getMessage());
if (status == 401 || status == 403) {
logger.error("Authentication failed. Check API key or Azure credentials.");
} else if (status == 404) {
logger.error("Deployment not found. Verify deployment name and endpoint.");
} else if (status == 429) {
logger.error("Rate limit exceeded. Please retry later.");
}
} catch (Exception e) {
// Handle all other exceptions
logger.error("Error in chat completion: {}", e.getMessage(), e);
}
}
}
In this quickstart, we walk you through setting up your local development environment with the Azure AI Foundry SDK. We write a prompt, run it as part of your app code, trace the LLM calls being made, and run a basic evaluation on the outputs of the LLM.
Copy the connection string and replace
The rest of this article shows how to use a ** **. Select Foundry Project at the top of this article if you want to use a Foundry Project instead. Which type of project do I need?
Prerequisites
- An Azure subscription. If you don’t have an Azure subscription, create a free account before you begin.
- A hub based project . If you’re new to Azure AI Foundry and don’t have a hub based project , select Foundry Project at the top of this article to use a Foundry project instead.
Set up your development environment
- Set up your development environment
-
Install these packages.
pip install azure-ai-inference azure-identity azure-ai-projects==1.0.0b10Different project types require different versions of theazure-ai-projectspackage. To avoid conflicts, create separate Python environments: use version1.0.0b10for hub based project s and the latest version for Foundry projects.
Deploy a model
Because you can customize the left pane in the Azure AI Foundry portal, you might see different items than shown in these steps. If you don’t see what you’re looking for, select … More at the bottom of the left pane.
- Sign in to Azure AI Foundry.
- Select a hub based project. If you don’t have a hub based project , select Foundry Project at the top of this article to use a Foundry project instead.
- Select Model catalog from the left pane.
- Select the gpt-4o-mini model from the list of models. You can use the search bar to find it.
-
On the model details page, select Deploy.

- Leave the default Deployment name. Select Deploy.
- Once the model is deployed, select Open in playground to test your model.
Build your chat app
Create a file named chat.py. Copy and paste the following code into it.from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
project_connection_string = "<your-connection-string-goes-here>"
project = AIProjectClient.from_connection_string(
conn_str=project_connection_string, credential=DefaultAzureCredential()
)
chat = project.inference.get_chat_completions_client()
response = chat.complete(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are an AI assistant that speaks like a techno punk rocker from 2350. Be cool but not too cool. Ya dig?",
},
{"role": "user", "content": "Hey, can you help me with my taxes? I'm a freelancer."},
],
)
print(response.choices[0].message.content)
Insert your connection string
Your project connection string is required to call the Azure OpenAI in Azure AI Foundry Models from your code.Find your connection string in the Azure AI Foundry project you created in the Azure AI Foundry playground quickstart. Open the project, then find the connection string on the Overview page.
<your-connection-string-goes-here> in the chat.py file.Run your chat script
Run the script to see the response from the model.python chat.py
Generate prompt from user input and a prompt template
The script uses hardcoded input and output messages. In a real app you’d take input from a client application, generate a system message with internal instructions to the model, and then call the LLM with all of the messages.Let’s change the script to take input from a client application and generate a system message using a prompt template.- Remove the last line of the script that prints a response.
-
Now define a
get_chat_responsefunction that takes messages and context, generates a system message using a prompt template, and calls a model. Add this code to your existing chat.py file:def get_chat_response(messages, context): system_message = "You are a helpful assistant." messages.append({"role": "system", "content": system_message}) response = openai.chat.completions.create( model="gpt-4o-mini", messages=messages) return response.choices[0].message.contentTheThe prompt template uses mustache format.get_chat_responsefunction could be easily added as a route to a FastAPI or Flask app to enable calling this function from a front-end web application. -
Now simulate passing information from a frontend application to this function. Add the following code to the end of your chat.py file. Feel free to play with the message and add your own name.
messages = [ {"role": "user", "content": "What is the weather in Tokyo?"} ] response = get_chat_response(messages, context) print(response)
python chat.py