pip install anthropic: Install the SDK and Send Your First Claude Request
Where to get an API key in the Claude Console, how to install the anthropic SDK, store the key securely with dotenv, and send your first request to Claude — from installation to printing the response.
How do I install the Anthropic Python SDK and send a first request?
Run pip install anthropic python-dotenv in a virtual environment (the SDK needs Python 3.10+), put ANTHROPIC_API_KEY in a .env file, then call client.messages.create with model, max_tokens and messages. The lesson uses claude-haiku-5-5; claude-3-haiku from Anthropic's original notebook was retired on April 20, 2026. Read the content block whose type is text.
API Fundamentals: Based on Anthropic Materials
6 short Python lessons built on Anthropic's open API fundamentals notebooks: setup, the Messages format, choosing a model, parameters, streaming and vision. Each lesson has a task checked by AI and a quiz.
The rest of this lesson opens after a free sign-up
Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.
What changed from Anthropic's original notebook
Anthropic recorded the course for Claude 3, and the lesson code now uses current models. Checked against PyPI and the Claude API docs on 9 Nov 2026.
| In the original notebook | In the lesson now | Why |
|---|---|---|
| Python 3.7.1 or later | Python 3.10 or later | The current anthropic package (2.7.0 on PyPI) requires Python 3.10+ |
| model="claude-3-haiku-20240307" | model="claude-haiku-5-5" for practice, claude-opus-5-5 for real work | claude-3-haiku was retired on April 20, 2026, and requests to retired models fail |
| model="claude-3-5-sonnet-20241022" (ready prompt) | model="claude-sonnet-5-5" | claude-3-5-sonnet was retired on October 28, 2025 |
| print(message.content[0].text) | Join the blocks of message.content with type == "text" | Current models use adaptive thinking, so a thinking block can come before the text block |
From an empty folder to Claude's answer
- python3 -m venv .venvA clean environment for the project
- pip install anthropic python-dotenvIn Jupyter: %pip install anthropic
- .env with ANTHROPIC_API_KEY


