# AI-901 hands-on labs

Seven runnable Python labs covering Domain 2 — the **55–60%** of the exam that is implementation. Do them in order; each builds on the last.

## One-time setup

```bash
cd labs
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

cp .env.example .env      # then fill it in
az login                  # auth is Microsoft Entra, not keys
```

### Getting the values for `.env`

| Variable | Where |
| -------- | ----- |
| `AZURE_AI_PROJECT_ENDPOINT` | [ai.azure.com](https://ai.azure.com) → your project → **Overview** → *Project endpoint* |
| `MODEL_DEPLOYMENT` | The **deployment name** you chose (not the model name) |
| `MULTIMODAL_DEPLOYMENT` | A vision/audio-capable deployment — often the same one |
| `IMAGE_DEPLOYMENT` | An image-generation deployment, e.g. `gpt-image-1` |
| `SPEECH_KEY` / `SPEECH_REGION` | Azure portal → your Speech or Foundry resource → **Keys and Endpoint** |
| `CONTENT_UNDERSTANDING_ENDPOINT` | `https://<resource-name>.services.ai.azure.com` |

## The labs

| # | File | Objective | Teaches |
| - | ---- | --------- | ------- |
| 01 | `01_first_call.py` | 2.1 | Project client, Entra auth, Responses API, `instructions`, temperature |
| 02 | `02_chat_client.py` | 2.1 | **Stateless vs stateful** — the `conversation=` argument |
| 03 | `03_prompt_agent.py` | 2.1 | Create a prompt agent, chat with it, version it |
| 04 | `04_text_analysis.py` | 2.2 | Text analysis two ways: generative JSON vs Azure AI Language |
| 05 | `05_speech.py` | 2.2 | STT, TTS, **SSML**, translation, and the full voice loop |
| 06 | `06_vision.py` | 2.3 | Images in prompts, multi-image comparison, image generation |
| 07 | `07_content_understanding.py` | 2.4 | Analyzers, the three extraction methods, async polling, confidence routing |

Every lab prints an **exam anchors** block at the end. Read it — that's the revision payload.

## Labs that degrade gracefully

04, 05, 06, and 07 skip their optional halves and print the exam-relevant code instead if the matching resource isn't configured. You can run the whole set with only a Foundry project and one chat deployment.

## Cost

All seven labs together cost pennies on a small deployment. The image generation in lab 06 is the most expensive single call — drop `quality` to `low` or comment out Part E if you're watching spend.

## Tidy up

Delete the `ai901-lab-agent` agent (portal → **Build → Agents**) and, when you're done with the exam, delete the whole resource group.
