Skip to main content
An OpenAI model decides when to search the web or read a page, and your code runs each call with the Keenable SDK. This page uses the Responses API. For Chat Completions, pass the SDK’s TOOLS unchanged and use the loop on Tool calling.

How the loop works

  1. Your code sends the question and the Keenable tools to client.responses.create.
  2. If the model wants the web, response.output holds one function_call item per call, each with a name, a call_id and arguments as a JSON string.
  3. Your code runs each call with run_tool_call and sends one function_call_output item per call, with the matching call_id, in a new request that sets previous_response_id.
  4. When the output holds no function_call item, response.output_text is the answer.

Prerequisites

  • An OpenAI API key in OPENAI_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)

Responses API function tools are flat: name, description and parameters sit next to type, with no nested function object. These are the Keenable SDK’s definitions in that shape:
OpenAI Responses format
strict is false because the search tool has optional arguments, and OpenAI’s strict mode requires every property to be listed in required. If you leave strict out, the Responses API tries to make the schema strict and falls back to non-strict when it can’t. 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 OpenAI’s SDK:
Save this program as openai-tools.mts or openai_tools.py. It asks a question, runs every tool call the model makes, and prints the answer:
Run it with npx tsx openai-tools.mts or python openai_tools.py. The program prints the model’s final answer. The question asks for sources, so the answer names the pages the model read. previous_response_id makes OpenAI keep the conversation between requests, so each follow-up sends only the tool outputs. To keep the conversation on your side instead, append response.output and your function_call_output items to an input list and send the whole list each time. If a tool call fails, the loop sends the error message as the output so the model can retry. Errors inside a tool call lists what run_tool_call raises.

Differences from other providers