Skip to main content
Claude decides when to search the web or read a page, and your code runs each call with the Keenable SDK. This page gives you the two tool definitions in Anthropic’s format and a complete loop for the Messages API.

How the loop works

  1. Your code sends the conversation and the Keenable tools to client.messages.create.
  2. If Claude wants the web, the response has stop_reason: "tool_use" and one tool_use block per call, each with a name, an id and a decoded input object.
  3. Your code runs each call with run_tool_call and sends every result back in one user message, as tool_result blocks with the matching tool_use_id.
  4. When stop_reason is anything other than tool_use, the text blocks hold Claude’s answer.

Prerequisites

  • An Anthropic API key in ANTHROPIC_API_KEY.
  • Python 3 or Node.js with tsx to run the program.
  • No Keenable key. The SDK searches without one. To raise the rate limit, set KEENABLE_API_KEY to an API key.

Tool definition (copy verbatim)

Anthropic’s Messages API takes each tool as name, description and input_schema. These are the Keenable SDK’s definitions in that shape:
Anthropic Messages format
The loop below builds this list from the SDK’s TOOLS at run time, so the definitions always match the SDK version you installed. If you paste the JSON instead, check the SDK column of the arguments table: an older run_tool_call drops any argument its version doesn’t offer.

Run the loop

Install the Keenable SDK and Anthropic’s SDK:
Save this program as claude-tools.mts or claude_tools.py. It asks a question, runs every tool call Claude makes, and prints the answer:
Run it with npx tsx claude-tools.mts or python claude_tools.py. The program prints Claude’s final answer. The question asks for sources, so the answer names the pages Claude read. If a tool call fails, for example on a page that can’t be fetched, the tool_result block carries is_error: true and the error message, so Claude can try another URL or query. Errors inside a tool call lists what run_tool_call raises.

Differences from other providers