Now that you know the API is just an HTTP doorway, let's walk through the one request you'll send a thousand times — and the reply that comes back. We'll use the Python SDK (with the raw HTTP shown alongside, so you always see what it builds). Every agent, tool, and prompt in this whole cert is this call, dressed up.
Three lines of setup, one call. Read it top to bottom — the comments say what each piece is. (No API key yet? Getting your API key is a 5-minute detour.)
# one-time: pip install anthropic + export ANTHROPIC_API_KEY=sk-... import anthropic client = anthropic.Anthropic() # finds your key in the environment msg = client.messages.create( # ← THE call. everything is this. model="claude-sonnet-4-6", # which Claude max_tokens=300, # longest reply you'll allow system="You are a concise, friendly assistant.", # standing instructions messages=[ # the conversation so far {"role": "user", "content": "Suggest a name for a tabby cat."}, ], ) print(msg.content[0].text) # → "How about Marmalade?"
Java bridge: if you did the Java/HTTP version, client.messages.create(...)
is exactly your HttpClient.send(POST /v1/messages, body) — the SDK is that POST, pre-written. The
msg object is the parsed JSON response.
Toggle between the Python you write and the raw HTTP it becomes. Same request — the SDK is just filling out the order slip for you:
The response is a JSON object (the SDK hands it to you as msg). You'll reach for four fields
constantly. Hover/click each field to see what it's for:
Click a field above.
The API remembers nothing between calls — there is no conversation stored on the server. To have a
multi-turn chat, you keep the messages list and resend the growing array each turn,
appending Claude's last reply as an assistant message. Watch the notebook grow:
system is a separate top-level parameter, not a message with
role:"system". Roles must alternate user → assistant → user. And you must set
max_tokens — it caps the reply, reserving output room in the window.client.messages.create(...) — is the whole
API. You pass a model, a top-level system prompt, an alternating user/assistant messages
list, and max_tokens. You get back a response object; grab the text at content[0].text,
check stop_reason, and read usage for token counts. It's stateless — you
resend the full history every turn. The SDK is just this HTTP call, pre-written.Next: the parameters that matter — what each knob does and when to turn it. Then how to read the API docs so you can answer your own questions. Practice it for real in the runnable Python exercises.