Call Claude and Print the Reply

Messages API

Part of: Your First API Call

Everything so far was setup: the counter, the JSON, the key, the limits. Now you walk up and place the order. About ten lines of Python sends a question to Claude and prints the answer. By the end of this lesson, every line of it will make sense. What it is Anthropic ships an SDK (Software Development Kit), a Python library that wraps the raw API so you don't hand-build the JSON. Install it once: An SDK builds the JSON request, attaches your key, sends it over the network, and hands you back a tidy object. You could do all that with the requests library and a hand-written dict, but the SDK is simply less to get wrong. How it works Here is the whole program: Read it top to bottom: - client : your connection. It reads the key from the environment (lesson 3) and holds it. - messages.create : the call itself. Here the request goes out and the response comes back (lesson 1). - model : which Claude to use. claude-sonnet-4-6 is a fast, capable default. - max tokens : a cap on how long the reply can be, measured in tokens. 200 is plenty for a sentence; set it too low and the answer gets cut off mid-thought. - messages : a list of turns . Each turn has a role (user is you) and content (what

Challenge: Validate the Conversation