Every module in this course calls Anthropic() and expects an API key to already be available. This module is that missing first step: what an API key is, how to get one, and how to give it to your code without ever writing it directly into a file.
It’s a secret string (starts with sk-ant-...) that identifies your Anthropic account to the API. Every request you make is billed to whichever account the key belongs to. Anyone who has the key can spend money on your account and see your usage — treat it exactly like a password, never like a username.
New accounts often start with a small amount of free trial credit, but you’ll need billing set up to keep using the API past that.
max_turns, mentioned back in Module 2) can’t run up an unexpectedly large bill.agentic-ai-course — so you can tell it apart from other keys later, and revoke it individually if needed.Every module’s README says export ANTHROPIC_API_KEY=your_key_here — here’s what that actually means and why it’s done this way. Setting it as an environment variable means the key lives in your terminal session, not in any file that could be committed to git or shared by accident. The Anthropic() client used throughout this course reads it from there automatically — that’s why no module ever passes a key directly in code.
macOS / Linux (bash or zsh):
export ANTHROPIC_API_KEY=sk-ant-your-actual-key-here
This only lasts for the current terminal session. To make it permanent, add that line to ~/.zshrc or ~/.bashrc and restart your terminal.
Windows (PowerShell):
$env:ANTHROPIC_API_KEY = "sk-ant-your-actual-key-here"
This also only lasts for the current session. For a permanent version: setx ANTHROPIC_API_KEY "sk-ant-your-actual-key-here" (then open a new terminal for it to take effect).
Alternative — a .env file, if you’d rather not touch shell config:
Create a file named .env in the module folder you’re running:
ANTHROPIC_API_KEY=sk-ant-your-actual-key-here
Then add python-dotenv to that module’s dependencies and add these two lines at the top of the script, before Anthropic() is called:
from dotenv import load_dotenv
load_dotenv()
If you do this, also create a .gitignore file containing .env — a .env file is exactly the kind of file that ends up committed by accident and leaks a key publicly. Module 5’s .gitignore shows this pattern already, for its database file.
Run this from any module’s folder (after pip install -r requirements.txt):
python -c "from anthropic import Anthropic; print(Anthropic().messages.create(model='claude-sonnet-4-5', max_tokens=20, messages=[{'role':'user','content':'Say hi in exactly 3 words.'}]).content[0].text)"
If you see a short reply printed back, your key is set up correctly and every module in this course is ready to run.
Delete it immediately from API Keys in the console (this is called revoking) and create a new one. A leaked key is not a “rotate it later” problem — anyone who has it can spend money on your account right away.
Module 1 — Your First Agent — now that a key is set up, the first real API call.