Using a model in Azure AI Foundry from a python project in VSCode

By Ivana Tilca · September 17, 2025 · 5 min read

This guide explains how to connect to a deployed model in Azure AI Foundry using Python and VSCode. It walks through creating a Python virtual environment, installing the required packages, and authenticating with Azure using the Azure CLI. Then, you create a Python script that connects to your Azure AI Foundry project endpoint, calls a deployed model such as GPT-4o, and sends a prompt using the chat completions API. The tutorial also shows where to find the project endpoint and the API version of the deployed model so you can run the script successfully from the terminal.

Requirements

VSCode

Python

Azure CLI

1 - Open VSCode and open up the folder using "File>Open Folder", in which you want to save your project.

2 - Select "Terminal>New terminal" in the top menu.

3- Create your python environment:

python3 -m venv env_name

4-Activate your environment

mac: source env_name/bin/activate

Win: .\env_name\Scripts\activate

5 - Install packages:

pip install openai azure-ai-projects azure-identity

6 - login into azure

az login

7 - create a python file <name>.py and include the following 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.get_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)

Note:

Where can i find the endpoint?

The endpoint of the project can be found in the "Overview" option from the left menu. The endpoint url of your project is the one that appears in the "Azure AI Foundry project endpoint"

Where do I get the api_version of my model?

Select under "My assets" the option "Models+endpoints" of the left menu. In there select the model you deployed.

In the end of the url of the endpoint of the model you will see api-version=... in this example my api_version = 2025-04-01-preview.

Once you have this information in your code, you can run in the terminal:

python <name>.py