Lesson 2: Getting Started with Azure AI Foundry
Learning Objectives
By the end of this lesson, you will be able to:
- Create an AI Foundry hub using Portal, CLI, Bicep, and SDK
- Create a project within a hub
- Navigate the AI Foundry portal
- Set up local development with VS Code and the SDK
📖 Official docs: Create an AI Foundry project
Creating Your First Hub
Option 1: Azure Portal
- Navigate to ai.azure.com
- Click + Create project
- Select New hub → configure name, region, resource group
- Review dependent resources (Storage, Key Vault, AI Services)
- Click Create
Option 2: Azure CLI
# Install the ML extension (AI Foundry uses the ML control plane)
az extension add --name ml --upgrade
# Create a resource group
az group create --name rg-ai-foundry-dev --location eastus
# Create an AI Hub
az ml workspace create \
--kind hub \
--name hub-myorg-dev \
--resource-group rg-ai-foundry-dev \
--location eastus
Option 3: Bicep (Infrastructure as Code)
// main.bicep — Create an AI Foundry Hub
@description('Name of the AI Hub')
param hubName string = 'hub-myorg-dev'
@description('Azure region for deployment')
param location string = resourceGroup().location
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: 'st${uniqueString(resourceGroup().id)}'
location: location
sku: { name: 'Standard_LRS' }
kind: 'StorageV2'
}
resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
name: 'kv-${uniqueString(resourceGroup().id)}'
location: location
properties: {
tenantId: subscription().tenantId
sku: { family: 'A', name: 'standard' }
enableRbacAuthorization: true
}
}
resource aiHub 'Microsoft.MachineLearningServices/workspaces@2024-04-01' = {
name: hubName
location: location
kind: 'Hub'
identity: { type: 'SystemAssigned' }
properties: {
friendlyName: hubName
storageAccount: storageAccount.id
keyVault: keyVault.id
}
}
output hubId string = aiHub.id
# Deploy the Bicep template
az deployment group create \
--resource-group rg-ai-foundry-dev \
--template-file main.bicep
Option 4: Python SDK
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Hub
from azure.identity import DefaultAzureCredential
ml_client = MLClient(
credential=DefaultAzureCredential(),
subscription_id="<subscription-id>",
resource_group_name="rg-ai-foundry-dev"
)
hub = Hub(
name="hub-myorg-dev",
location="eastus",
display_name="My Organization Dev Hub"
)
created_hub = ml_client.workspaces.begin_create(hub).result()
print(f"Hub created: {created_hub.name}")
Creating a Project Within a Hub
Azure CLI
az ml workspace create \
--kind project \
--name proj-chatbot \
--resource-group rg-ai-foundry-dev \
--hub-id /subscriptions/<sub>/resourceGroups/rg-ai-foundry-dev/providers/Microsoft.MachineLearningServices/workspaces/hub-myorg-dev
Python SDK
from azure.ai.ml.entities import Project
project = Project(
name="proj-chatbot",
hub_id=created_hub.id,
display_name="Customer Chatbot"
)
created_project = ml_client.workspaces.begin_create(project).result()
print(f"Project created: {created_project.name}")
Navigating the AI Foundry Portal
The portal at ai.azure.com is organized into key sections:
| Section |
Purpose |
| Home |
Recent projects, quick actions, learning resources |
| Model catalog |
Browse and deploy 1,600+ models |
| Playgrounds |
Interactively test models (Chat, Completions, Images, Audio) |
| Prompt flow |
Build and test multi-step AI workflows |
| Evaluation |
Run quality and safety evaluations |
| Deployments |
Manage model endpoints |
| Data |
Upload and manage datasets |
| Agents |
Build AI agents with tools and data access |
Portal Workflow
Model Catalog → Playground → Prompt Flow → Evaluation → Deployment
↓ ↓ ↓ ↓ ↓
Select model Prototype Build pipeline Validate Go live
Setting Up VS Code Integration
1. Install Required Extensions
- Azure Account — Sign in to Azure
- Azure AI Foundry — Project management and debugging
- Python — Python development support
- Jupyter — Notebook support for experimentation
2. Install the SDK Packages
# Core packages for AI Foundry development
pip install azure-ai-projects # Project management
pip install azure-ai-inference # Model inference (chat, embeddings)
pip install azure-identity # Authentication
pip install azure-ai-evaluation # Evaluation framework
# Optional but recommended
pip install azure-ai-ml # ML workspace management
pip install python-dotenv # Environment variable management
# .env file — store your configuration
AZURE_SUBSCRIPTION_ID=your-subscription-id
AZURE_RESOURCE_GROUP=rg-ai-foundry-dev
AZURE_AI_HUB_NAME=hub-myorg-dev
AZURE_AI_PROJECT_NAME=proj-chatbot
# connect.py — verify your connection
import os
from dotenv import load_dotenv
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
load_dotenv()
project = AIProjectClient(
credential=DefaultAzureCredential(),
endpoint="https://hub-myorg-dev.services.ai.azure.com/api",
project_name=os.getenv("AZURE_AI_PROJECT_NAME")
)
print("✅ Connected to AI Foundry project!")
print(f" Project: {project._config.project_name}")
Understanding the SDK Ecosystem
| Package |
Purpose |
Install |
azure-ai-projects |
Manage projects, connections, agents |
pip install azure-ai-projects |
azure-ai-inference |
Call models (chat, embeddings, images) |
pip install azure-ai-inference |
azure-ai-evaluation |
Evaluate model quality and safety |
pip install azure-ai-evaluation |
azure-ai-ml |
Manage hubs, projects, compute (control plane) |
pip install azure-ai-ml |
azure-identity |
Authentication (DefaultAzureCredential) |
pip install azure-identity |
openai |
OpenAI-compatible API (works with Azure) |
pip install openai |
💡 Tips: Getting Started Best Practices
- Use managed identity from day one — Avoid API keys; use
DefaultAzureCredential for all SDK calls
- Tag your resources — Apply
environment, team, and project tags for cost and access tracking
- Start in the playground — Prototype prompts interactively before writing code
- Use
.env files — Never hard-code connection strings or keys in source code
- Enable diagnostic logging — Turn on Application Insights during hub creation
- Version control your Bicep — Infrastructure as Code from the start
# ✅ Do this — managed identity
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
# ❌ Not this — hardcoded keys
api_key = "sk-abc123..." # Never do this!
Summary
| Method |
Best For |
| Portal |
Quick experimentation and learning |
| CLI |
Scripted setup and CI/CD pipelines |
| Bicep |
Repeatable infrastructure deployments |
| SDK |
Application-level resource management |
Additional Resources