Skip to content

Your first real call

Read · 1 of 2

Look familiar?

Save this as first.py and run it. It's the call you've been making all course: client.messages.create, a list of messages, a reply with .content blocks.

Two differences you'll notice at once: the answer is different every run, and reply.usage tells you exactly how many tokens it used, which is what you pay for.

1import anthropic
2
3client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from your environment
4
5reply = client.messages.create(
6 model="claude-haiku-4-5-20251001",
7 max_tokens=300,
8 messages=[{"role": "user", "content": "Explain recursion to a 10-year-old in two sentences."}],
9)
10print(reply.content[0].text)
11print("tokens in:", reply.usage.input_tokens, "out:", reply.usage.output_tokens)
$python3 first.py
Read this lesson as text

The same call you've made a hundred times, now to a real model.

Look familiar?

Save this as first.py and run it. It's the call you've been making all course: client.messages.create, a list of messages, a reply with .content blocks.

Two differences you'll notice at once: the answer is different every run, and reply.usage tells you exactly how many tokens it used, which is what you pay for.

import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY from your environment

reply = client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=300,
    messages=[{"role": "user", "content": "Explain recursion to a 10-year-old in two sentences."}],
)
print(reply.content[0].text)
print("tokens in:", reply.usage.input_tokens, "out:", reply.usage.output_tokens)
python3 first.py

Picking a model

Haiku (claude-haiku-4-5-20251001): fast and cheap. Great for routing, classifying, simple tool use, and running evals many times.

Sonnet (claude-sonnet-5-5): the default for most agents. Strong reasoning and tool use at a sensible price.

Opus (claude-opus-5-5): the most capable, for the hardest multi-step work. Use it when Sonnet isn't enough, and measure that with your evals.

A common pattern: a cheap model routes and a stronger one does the hard step. Your evals from module 10 tell you which is good enough.