Prerequisites

Dev Environment Setup

Before writing any code, you need three things working: VS Code as your editor, Jupyter notebooks for interactive development, and the Anthropic Python SDK connected to a valid API key. This module gets all three running and ends with a verified "Hello Claude" test.

Answer key Module0_Complete.ipynb

1. What You'll Need

  • Python 3.9 or later, check with python --version or python3 --version
  • VS Code, download from code.visualstudio.com
  • An Anthropic API key, obtained from console.anthropic.com
  • ~10 minutes and a terminal

2. Install VS Code Extensions

Open VS Code and install these two extensions from the Extensions panel (Ctrl+Shift+X / Cmd+Shift+X):

  • Python, publisher: ms-python. Enables Python language support, linting, and virtual environment detection.
  • Jupyter, publisher: ms-toolsai. Lets you run .ipynb notebooks directly inside VS Code without launching a browser.

3. Create Your Project Folder

Pick a home for your lab files. All advanced modules will build on the same notebook, so one folder is all you need.

bash
mkdir claude-architect-lab
cd claude-architect-lab

4. Set Up a Virtual Environment

A virtual environment keeps the SDK and its dependencies isolated from the rest of your system, important when you're working with multiple Python projects.

bash
# Create the environment
python -m venv .venv

# Activate it
# macOS / Linux:
source .venv/bin/activate

# Windows (PowerShell):
.venv\Scripts\Activate.ps1

# Windows (Command Prompt):
.venv\Scripts\activate.bat

Your terminal prompt should now show (.venv) to confirm it's active.

5. Install Dependencies

bash
pip install anthropic python-dotenv ipykernel
  • anthropic, the official Python SDK for the Claude API
  • python-dotenv, loads your .env file so the API key is never hardcoded
  • ipykernel, registers your virtual environment as a Jupyter kernel so VS Code can find it

6. Get Your API Key

  • Go to console.anthropic.com and sign in (or create a free account).
  • Navigate to API Keys in the left sidebar.
  • Click Create Key, give it a name like "architect-lab", and copy the key, it starts with sk-ant-.

You only see the full key once, so copy it immediately.

7. Store Your Key Safely

Create two files in your project folder:

.env
ANTHROPIC_API_KEY=sk-ant-api03-YOUR-KEY-HERE
.gitignore
.env
.venv/
__pycache__/
*.pyc
.ipynb_checkpoints/
Never commit your API key. The .gitignore above ensures .env stays local. If you accidentally push a key, rotate it immediately in the Anthropic console, old keys can be used by anyone who finds them in your git history.

8. Create Your Lab Notebook

  • Open your project folder in VS Code: File → Open Folder
  • Create a new file named lab.ipynb (File → New File, then save with the .ipynb extension).
  • VS Code will open it as a notebook. In the top-right corner, click Select Kernel.
  • Choose Python Environments → select the .venv you just created. If it doesn't appear, run Python: Select Interpreter from the command palette first.

9. Hello Claude, Your First Cell

Add a new code cell and paste the following. Run it with Shift+Enter.

python
import anthropic
from dotenv import load_dotenv

load_dotenv()  # reads ANTHROPIC_API_KEY from your .env file

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=256,
    messages=[
        {"role": "user", "content": "In one sentence, what is the Claude API?"}
    ]
)

print(message.content[0].text)

If everything is configured correctly, you should see a one-sentence response from Claude. That's your environment confirmed.

10. Understanding the Response Object

Before moving to Module 1, it's worth knowing what the API returned. Add a second cell:

python
print("Stop reason:", message.stop_reason)
print("Input tokens:", message.usage.input_tokens)
print("Output tokens:", message.usage.output_tokens)
print("Model:", message.model)
  • stop_reason, "end_turn" means Claude finished naturally. The exam tests this heavily.
  • usage, input and output token counts used to calculate cost.
  • model, confirms which model version actually ran your request.
Keep your notebook cells small and purposeful. Each lab module adds new cells to this same lab.ipynb. A well-structured notebook with clear headings and focused cells is also good practice for the structured output modules later in the lab.

Troubleshooting

ProblemMost likely causeFix
AuthenticationError.env not found or key is wrongCheck the file is in the project root, not a subfolder. Confirm no extra spaces around the =.
Kernel not listed.venv not registered with JupyterRun python -m ipykernel install --user --name .venv inside your activated environment.
ModuleNotFoundError: anthropicWrong Python environment activeConfirm (.venv) is in your terminal prompt, then re-run pip install anthropic.
VS Code shows "No kernel"Jupyter extension not installedInstall the Jupyter extension from the Extensions panel and reload VS Code.

Lab Exercise: Environment Verification & Response Anatomy

Self-driven lab Module0_Self_Driven_Lab.ipynb

Objective: build a clean local notebook workspace and verify that Claude requests run through the configured API key.

  1. Create or verify the project folder, virtual environment, `.env`, and Jupyter kernel setup.
  2. Run a minimal Claude request and print the returned text, model name, token usage, and stop reason.
  3. Intentionally break one setup assumption, such as a missing key or wrong kernel, then document the error and fix.
  4. Record the environment checklist you would hand to a teammate before starting the agent labs.
Expected Deliverable

A working notebook environment plus a short troubleshooting checklist.