Skip to content
Academy ofAI Learning

Learn it by doing it

How to make my first API call

Watch it done first, then do it yourself in the lessons below. Pause the walkthrough at any step and try it on your own computer.

Watch it done: make your first Claude API call in Python

$

Step 1 of 6

Make a folder for the project and move into it. You need Python 3.10 or later.

  1. Make a folder for the project and move into it. You need Python 3.10 or later. Type: mkdir claude-quickstart && cd claude-quickstart.
  2. Create a virtual environment and switch it on, so the SDK installs into this project only. Type: python3 -m venv .venv && source .venv/bin/activate.
  3. Install the official Python SDK. Type: pip install anthropic. pip downloads and installs the SDK and the packages it needs.
  4. Create a key on the API keys page of the Claude Console, then put it in this variable in place of the placeholder. The key never goes in your code. Type: export ANTHROPIC_API_KEY="your-api-key-here".
  5. Create quickstart.py. The client finds your key in the environment, and messages.create sends one request with the three required fields: model, max_tokens and messages. Create quickstart.py containing: import anthropic client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY message = client.messages.create( model="claude-opus-5-5", max_tokens=1000, messages=[ {"role": "user", "content": "Suggest three subject lines for our November newsletter."} ], ) for block in message.content: if block.type == "text": print(block.text)
  6. Run it. The reply is a list of content blocks, so the script prints only the text blocks rather than assuming the first block is text. Type: python quickstart.py. prints Claude's reply, for example three subject lines. The wording is different every time.

Commands and code from the official Claude API quickstart and Python SDK docs, checked 18 November 2026. The Windows virtual environment command is from the Python venv docs. The key shown is a placeholder. Lines marked Note describe what happens and are not real output.

From the lesson Make your first Claude API call.

Your path: 1 lesson

0 of 1 done · about 8 min

Do them in this order. Each one has you try it for real, then checks you can.

  1. 1

    Level 6: Building with the Claude API · 8 min

    Make your first Claude API call

    How to get a Claude API key from the Console, install the Python SDK, send your first Messages API request and read what comes back.

    Start

Next: Make your first Claude API call. Start it now

These lessons are part of the Professional Diploma, unit D2: Extending Claude: skills, MCP and integrations. See what it covers