Before building an agent, get a working Python environment with the Anthropic SDK and an API key, and make your first model call. This is the foundation every later lesson builds on.
Why: an agent is just code that calls a model in a loop, so you need three things — Python, the SDK, and an API key. When: do this once; every lesson assumes it works. Where: the prerequisites (basic Python, a terminal, and how an HTTP API works) are enough — you do not need a backend framework.
You will build agents in Python. You need:
[ ] Python 3.10+ -> python --version
[ ] A terminal -> to run scripts and install packages
[ ] An Anthropic API key -> console.anthropic.com -> API Keys
The same agent patterns work in any language and with any model
provider — this course uses Python + Claude so the code is concrete.Why: the SDK wraps the HTTP API so you call the model with one function instead of hand-building requests. Where: set the key as an environment variable, never hard-coded in your script — committing a key to git leaks it.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install anthropic
# Set your key for this terminal session
export ANTHROPIC_API_KEY="sk-ant-..." # Windows: set ANTHROPIC_API_KEY=...Why: an agent is a loop around this one call, so make sure it works in isolation first. Where: the client reads ANTHROPIC_API_KEY from the environment automatically — no key in the code.
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the env
response = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.content[0].text)Why: a response is a list of content blocks, not a plain string — once tools and thinking are involved, the text is not always block zero. When: use this helper in every lesson to pull the text out safely.
def text_of(response):
"""Concatenate the text blocks of a model response."""
return "".join(b.text for b in response.content if b.type == "text")
response = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hello."}],
)
print(text_of(response))