Check my levelCoursesProgramsFor teamsPricing
UKSign inSign up
Check my levelCoursesProgramsFor teamsPricingClaude quizPromptsBlogFAQSearchSign upUK
AcademlCoursesAPI Fundamentals: Based on Anthropic MaterialsFirst Steps: Installation and Your First Request
A streamed answer: each line is one word longer than the previous oneClaude Code terminal: the claude -p command with Read and Edit allowedRetries after a 429 error: each pause is twice as long, then success
Get started free
Course

API Fundamentals: Based on Anthropic Materials

Module 1 · Getting Started with Claude SDK
01First Steps: Installation and Your First Request
Module 2 · Messages API Format
02Messages API: Format, Response Object, and Chatbot
Module 3 · Claude Models
03Choosing a Model: Speed, Capabilities, Cost
Module 4 · Generation Parameters
04max_tokens, stop_sequences, system prompt, and effort
Module 5 · Streaming
05Streaming: Real-Time Responses
Module 6 · Vision: Working with Images
06Vision: Images in Claude Prompts
API Fundamentals: Based on Anthropic Materials · Lesson 1

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.

20 min readUpdated Nov 9, 20263 questions in quizReady prompt included

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.

Start free: 7 days of full access →
Lesson 1 of 6free after sign-up

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.

Course program →

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.

Sign up freeOr a trial lesson, no sign-up →

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 notebookIn the lesson nowWhy
Python 3.7.1 or laterPython 3.10 or laterThe 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 workclaude-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
Sources: PyPI anthropic, Claude API docs “Get started”, “Model deprecations”, “Models overview”.

From an empty folder to Claude's answer

  1. python3 -m venv .venvA clean environment for the project
    →
  2. pip install anthropic python-dotenvIn Jupyter: %pip install anthropic
    →
  3. .env with ANTHROPIC_API_KEY
In this lesson
Getting an API KeyInstalling the SDKStoring Your API KeyInitializing the ClientYour First Request to ClaudeThree Required ParametersWhat Are Tokens?Without PythonPracticeReady promptQuiz
CoursesLLM coursesFor teamsPricingFAQBlogAboutPrivacy
© 2026 AcademlDevelopment & promotion —MMIX — Marketing Mix
Key from the Claude Console; add .env to .gitignore
→
  • client.messages.create(...)model, max_tokens, messages
    →
  • Read the text blocksblock.type == "text" → block.text
    →
  • Anthropic() reads ANTHROPIC_API_KEY from the environment by itself; call load_dotenv() first if the key lives in .env.

    Notes for running the lesson today

    Checked on 9 Nov 2026 (Claude API docs and PyPI).

    • Every Claude 3 model in Anthropic's original notebooks is retired: claude-3-haiku-20240307 on April 20, 2026, claude-3-5-sonnet on October 28, 2025, claude-3-opus on January 5, 2026. Anthropic suggests starting with claude-opus-5-5 ($4 / $20 per million input / output tokens); claude-haiku-5-5 is the cheapest current model, from $0.10 per million input tokens.
    • A fresh pip install anthropic gives SDK 2.x, which sends API version 2026-10-21. That version removes temperature, top_p and top_k, and any value returns a 400 error. Lesson 4 explains how to steer the output without them.
    • To read the answer on current models: "".join(b.text for b in message.content if b.type == "text"). A thinking block may or may not come before the text, and its text is omitted by default.
    • “ANTHROPIC_API_KEY not set” with an existing .env usually means load_dotenv() ran after os.getenv() or the .env file sits in a different folder from where you start Python.
    • You create the key in the Claude Console at platform.claude.com, and API requests are billed separately from a Claude.ai subscription.

    Sources we checked

    • Claude API docs: Get started
    • PyPI: anthropic
    • Claude API docs: Model deprecations
    • Claude API docs: Models overview
    • Claude API docs: Migrating to API version 2026-10-21
    • anthropics/courses: Anthropic API fundamentals (archived)

    FAQ

    How do I install the anthropic package for Python?+

    Run pip install anthropic, ideally inside a virtual environment (python3 -m venv .venv, then activate it). The current version needs Python 3.10 or newer. In Jupyter use %pip install anthropic so the package lands in the kernel's environment. Add python-dotenv if you keep the key in a .env file.

    Why does my script say ANTHROPIC_API_KEY is not set?+

    Call load_dotenv() before os.getenv("ANTHROPIC_API_KEY"), and check that .env sits in the folder you run Python from. If you export ANTHROPIC_API_KEY in your shell, Anthropic() picks it up without dotenv. Keep the key out of the code: once committed to git, it leaks.

    Which model name should I use in my first request?+

    claude-haiku-5-5 is the cheapest current model and fine for practice; Anthropic recommends claude-opus-5-5 as the starting point for real work. The lesson uses claude-haiku-5-5 and claude-sonnet-5-5 in the ready prompt. The original notebook's claude-3-haiku-20240307 and claude-3-5-sonnet-20241022 are retired, and requests to them fail.

    Why does message.content[0].text fail?+

    Current models use adaptive thinking, so the first content block can be a thinking block with no text field. Loop over message.content and take the blocks whose type is "text", as the quickstart in Anthropic's docs does.

    Which parameters does client.messages.create need?+

    Three: model (the model id), max_tokens (the upper limit on response length; the model can stop earlier) and messages (the conversation as a list of role/content pairs). Lesson 2 covers the format of messages and the response object.

    Is this lesson free?+

    Yes. It is lesson 1 of 6 in “API Fundamentals: Based on Anthropic Materials”, and a free account keeps the first two lessons of every Academl course open for good. A free account opens all lessons for 7 days with no card; after that Pro costs $9 a month or $79 a year.

    Related lessons and courses

    Lesson 2: the Messages API format →Anthropic API fundamentals course →Claude API from A to Z →Claude Opus 5.5: API pricing and free trial →Anthropic tool use course →The agent loop in Python →How to write tool descriptions for Claude function calling →

    Next: messages, models, streaming and images

    The next lessons cover the Messages format and a simple chatbot, choosing a model by speed and cost, system prompts, streaming and vision. A free account opens all 6 lessons for 7 days.

    Create a free account →

    Getting an API Key

    Keys are created in the Claude Console at platform.claude.com (the old console.anthropic.com address redirects there). Create a key there and store it somewhere safe. The Console also has a playground (formerly Workbench) where you can try a request without code.