Chapter 1 · Part 1

Get a key & say hello

Every other hands-on course here runs entirely on your laptop. This one is different: it talks to a real cloud API — Anthropic's Claude API, the same one that powers production AI products. By the end you'll have a command-line chatbot that streams its replies and can call your own code. It's the applied companion to the ChatGPT, Prompting and AI-Costs courses.

One heads-up: this course needs an Anthropic API key and costs a few cents to run — the only course in the track that isn't free. You'll set a spending cap in Chapter 6.

1 · Get an API key

Sign in at platform.claude.com, open API keys, and create one. It looks like sk-ant-.... Copy it now — you can't view it again after leaving the page. New accounts include some free credit to get started.

2 · A virtual environment + the SDK

Make an isolated environment and install the official Python SDK:

terminal
python3 -m venv .venv
source .venv/bin/activate     # Windows: .venv\Scripts\Activate.ps1
pip install anthropic

3 · Store the key as an environment variable

Never put your key in code — it would leak the moment you share or commit the file. Instead set it as an environment variable; the SDK reads it automatically:

terminal
export ANTHROPIC_API_KEY="sk-ant-...your key here..."

(On Windows PowerShell: $env:ANTHROPIC_API_KEY = "sk-ant-...". To make it permanent, add the line to your shell profile.)

4 · Say hello

Create hello.py. Notice there's no API key in the file — Anthropic() picks it up from the environment:

hello.py
from anthropic import Anthropic

client = Anthropic()

message = client.messages.create(
  model="claude-opus-4-8",
  max_tokens=1024,
  messages=[
      {"role": "user", "content": "Say hello and tell me one fun fact about octopuses."}
  ],
)

print(message.content[0].text)
terminal
python hello.py
Hello! Here's a fun one: an octopus has three hearts — two pump blood
through the gills, and the third pumps it to the rest of the body.

That's a real language model answering over the network, in five lines. The response text lives at message.content[0].text — we'll see why it's nested like that next chapter, where we take the request apart piece by piece.