📊 We use cookies & analytics to improve your experience. Learn more
Latest

Claude Mastery — From First Prompt to Advanced Workflows Module 3 · Lesson 10 of 15

0% Exit to course

Module 3 · Files, tools and your own data Lesson 10 of 15

The Anthropic API and your first script

Learning objective

Claude is available over an API billed per token, with a large context window and native support for tool use and long documents. You do not need this to finish the course, and you do not need it for a fresher job either — but an afternoon here is what turns "I have used Claude" into "I have built with it", which is a different sentence in an interview.

The concept

Claude is available over an API billed per token, with a large context window and native support for tool use and long documents. The idea is simple: the same model you have been chatting with also answers a web request, so you can put it inside a script, a spreadsheet or a page. A key identifies you; a request sends the text; a response comes back as data.

The reason to try it once, even if you never build anything: it makes the chat version less mysterious. You see that the whole conversation is text in and text out, that your instructions are literally lines of a request, and that "the model" is one parameter among several.

A first call looks like this:

Python
import anthropic

client = anthropic.Anthropic()   # reads ANTHROPIC_API_KEY

msg = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=300,
    messages=[{
        "role": "user",
        "content": "In three sentences, what is a data analyst? Be concrete.",
    }],
)

print(msg.content[0].text)

Common mistakes

The mistake is sending a 200-page document on every request because the window is large. Tokens cost money and time; send the pages the question is about.

Worked example

A script that reads a folder of PDFs and returns a one-paragraph abstract of each is the classic first job for this API, and it is genuinely useful for a student with forty papers.

Your practice task

Get a key, run one request that works, and change one word in it to see the answer change. That is the whole of the first afternoon.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

Claude is available over an API billed per token, with a large context window and native support for tool use and long documents.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.