Messages API and Tool Use
Explore how to use Anthropic's Messages API to create and debug Claude-based applications. Understand message construction, tool integration, handling stop reasons, and running tool use loops to build efficient, explainable agent workflows.
Every Claude product an FDE builds starts from the same place. Chat assistants, document reviewers, and multi-step agents all send requests to one endpoint, the Messages API, and read back responses in one shape. Higher-level tools such as the Agent SDK sit on top of this layer.
Fluency at this layer pays off in two ways. It lets us build a working integration in a customer’s environment within hours, and it lets us explain exactly what an agent did when something goes wrong. Interviewers who ask us to build or debug a Claude workflow expect that fluency.
The examples here use the Anthropic Python SDK. Each one passes our Anthropic API key to the client through the api_key parameter.
Anatomy of a Messages API call
The Messages API is Anthropic’s interface for sending a conversation to Claude and receiving Claude’s next turn. A request names a model, sets an output limit, and passes the conversation as a list of messages. An optional system prompt sets Claude’s role and rules for the whole conversation.
The code below sends one question to Claude as a support assistant for a home goods store.
Line 4:
anthropic.Anthropic()creates the client, andapi_keypasses our Anthropic API key so every request is authenticated.Lines 6–13:
client.messages.createsends the request.modelpicks the Claude model,max_tokenscaps the length of the reply,systemsets the assistant’s role, andmessagesholds the conversation.Lines 16–18: The loop reads
response.content, a list of content blocks, and prints only blocks whosetypeistext.Lines 20–22:
stop_reasonexplains why Claude stopped, andusagereports the input and ...