Day 1, 25 minutes · beginner
Why it matters
A plain Claude API call can only use what is in the text you send. Ask it whether a shop has a plant in stock and it has two choices: guess, or say it does not know. Tool use fixes that. You tell Claude which functions your program has, and Claude asks your program to run one when it needs the answer. That is how Claude gets to live data, your own files and your own systems.
This course follows Margriet, who runs a small made-up plant shop, Copperleaf Plants. Customers ask her the same three things all day: is it in stock, what does it cost, when are you open. Over seven days you build a small helper that answers those questions with her real shop data. Today you set up the project and send your first request with a tool in it. At the end you have seen Claude ask for your tool instead of guessing, and you know who runs what.
Before you start
This course builds on Claude API for Beginners. You need what you made there: a Claude Console account with credits, an API key in a .env file, Python with the anthropic SDK (or Node.js with @anthropic-ai/sdk), and one Messages API call that worked. The code is in Python. Some lessons also give a Node version.
The words you need today
- Tool: a function that Claude may ask your program to run. The docs also call this function calling. A tool has a name, a description and a list of the inputs it takes.
- JSON: a plain text format for data, with names and values in curly brackets, such as
{"plant": "monstera"}. - Schema: a description of what an input must look like: which fields, which types, which are required. Tool inputs are described with JSON Schema, a standard way to write such a description in JSON.
- tool_use block: the part of Claude's response that asks for a tool. It holds the tool's
name, theinputClaude wants to pass, and anid. - stop_reason: why Claude stopped. In the beginners course you saw
end_turn. When Claude wants a tool, it istool_use.
Claude never runs anything itself
This is the most important idea of the course. The docs describe tool use as a contract: you say which operations exist and what their inputs look like, and Claude decides when to call them. Claude does not run your code. It sends back a structured request, your program runs the function, and you send the result back. Claude never sees your code, only the schema you gave and the result you return.
So for every tool, someone has to run it. The docs sort tools by where they run:
| Kind | Who writes the schema | Who runs it | Example |
|---|---|---|---|
| Your own tools (client tools) | you | your code | Margriet's stock check |
| Anthropic-schema tools (also client tools) | Anthropic | your code | bash, text_editor |
| Server tools | Anthropic | Anthropic's servers | web_search, web_fetch, code_execution |
This course is mostly about the first kind. Lesson 6 tries a server tool, web search.
The loop in one picture
With your own tools, every tool call is a round trip:
- You send a request with a
toolslist and the customer's question. - Claude answers with
stop_reasonset totool_useand one or moretool_useblocks. - Your code runs each tool.
- You send the results back in a new request.
- Claude either asks for another tool or writes its final answer.
Today you do steps 1 and 2 only, so you can look at the request Claude sends you. Lesson 3 does the rest.
When tools are worth it
The docs give a simple test: use a tool when the task needs something Claude cannot do from text alone. Fresh data (stock, prices, today's hours), actions with an effect (saving a file, sending a message) and your own systems are good reasons. Summaries, translations and general questions are not: a tool call adds at least one extra round trip.
The steps
- Make a new project folder with a virtual environment, the SDK and your
.envfile. - Create
shop.py: Margriet's stock, prices and opening hours, and three plain Python functions. No AI yet. - Test the functions on their own.
- Send your first request with a tool and read the
tool_useblock. - Ask a question that needs no tool and compare.
Follow the steps below.
Today's actions
Ticks are not saved without an accountDo it in Claude API
Claude API
- On macOS or Linux: open a terminal and run these lines. They make the project folder and a virtual environment and install the SDK. Then copy .env and .gitignore from your beginners course project into copperleaf-tools.
mkdir copperleaf-tools cd copperleaf-tools python3 -m venv .venv source .venv/bin/activate pip install anthropic python-dotenv - On Windows: open PowerShell and run these lines instead. Then copy .env and .gitignore from your beginners course project into copperleaf-tools, for example in File Explorer.
mkdir copperleaf-tools cd copperleaf-tools python -m venv .venv .venv\Scripts\Activate.ps1 pip install anthropic python-dotenv - In your code editor, create
shop.pywith this code: Margriet's made-up stock, prices and opening hours, and three plain functions. There is no AI in this file."""Copperleaf Plants: made-up shop data and the functions Claude may ask for.""" STOCK = {"monstera": 4, "pothos": 12, "snake plant": 0, "peace lily": 7} PRICES = {"monstera": 24.50, "pothos": 9.95, "snake plant": 18.00, "peace lily": 14.75} HOURS = { "monday": "closed", "tuesday": "10:00 to 18:00", "wednesday": "10:00 to 18:00", "thursday": "10:00 to 20:00", "friday": "10:00 to 18:00", "saturday": "09:00 to 17:00", "sunday": "closed", } def known_plant(plant): name = plant.strip().lower() if name not in STOCK: raise ValueError(f"Unknown plant '{plant}'. Copperleaf sells: {', '.join(STOCK)}.") return name def check_stock(plant): name = known_plant(plant) return f"{STOCK[name]} x {name} in stock today" def get_price(plant): name = known_plant(plant) return f"{name}: EUR {PRICES[name]:.2f} each" def get_opening_hours(day): name = day.strip().lower() if name not in HOURS: raise ValueError(f"Unknown day '{day}'. Use a day name such as saturday.") return f"{name}: {HOURS[name]}" - Test the functions without the API: run
python -c "import shop; print(shop.check_stock('monstera'))". You see 4 x monstera in stock today. Tryshop.get_price('pothos')the same way. - Create
first_tool_call.pywith this code. It sends one question with one tool and prints what Claude sends back.import json import sys from dotenv import load_dotenv import anthropic load_dotenv() client = anthropic.Anthropic() tools = [ { "name": "check_stock", "description": "Check how many plants of one kind Copperleaf Plants has in stock today.", "input_schema": { "type": "object", "properties": { "plant": {"type": "string", "description": "The plant name, for example monstera"} }, "required": ["plant"], }, } ] question = " ".join(sys.argv[1:]) or "Do you have a monstera in stock?" response = client.messages.create( model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=[{"role": "user", "content": question}], ) print("stop_reason:", response.stop_reason) for block in response.content: if block.type == "text": print("text:", block.text) elif block.type == "tool_use": print("tool_use:", block.name, json.dumps(block.input), "id:", block.id) - Run
python first_tool_call.py. You should seestop_reason: tool_useand a tool_use line withcheck_stock, the input{"plant": "monstera"}and an id. Nothing ran: Claude only asked. - Now run
python first_tool_call.py "What is a monstera?". Claude most likely answers in text withstop_reason: end_turn, because that needs no shop data. Copy both outputs intotool-use-notes.txt. - For Node instead of Python: in a new folder with your .env, run
npm init -y,npm pkg set type=moduleandnpm install @anthropic-ai/sdk, save this asfirst_tool_call.mjsand runnode --env-file=.env first_tool_call.mjs.import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const tools = [ { name: "check_stock", description: "Check how many plants of one kind Copperleaf Plants has in stock today.", input_schema: { type: "object", properties: { plant: { type: "string", description: "The plant name, for example monstera" } }, required: ["plant"] } } ]; const question = process.argv.slice(2).join(" ") || "Do you have a monstera in stock?"; const response = await client.messages.create({ model: "claude-opus-5-5", max_tokens: 1024, tools, messages: [{ role: "user", content: question }] }); console.log("stop_reason:", response.stop_reason); for (const block of response.content) { if (block.type === "text") { console.log("text:", block.text); } else if (block.type === "tool_use") { console.log("tool_use:", block.name, JSON.stringify(block.input), "id:", block.id); } }
Note: Your answers will differ a little from run to run. If you see AuthenticationError, the .env file did not come along: check that it is in the new folder. The rest of the course uses Python; lesson 7 has a full Node version.
Paid planPay as you go: buy prepaid credits in the Claude Console (minimum 5 US dollars). There is no free tier. Max, Ultra and Team plans include monthly API credits.
Create a free account to save your progress
Free, and no payment details. Your ticks and finished lessons are kept, on every device.
Create a free account I already have an accountCreate a free account to save your progress. Sign in or sign up