Common mistakes in Responses API tool call example

Wrong function name & argument handling in tool call example.

In the Responses API documentation example for tool calls (horoscope example),
there are a few mistakes in the response.output.forEach block.

Docs currently show:

if (item.name == "get_horoscope"):
  const horoscope = get_horoscope(JSON.parse(item.arguments))
  input_list.push({
    type: "function_call_output",
    call_id: item.call_id,
    output: json.dumps({ horoscope })
  })

Issues:

  1. Uses == and : (Python-style) instead of correct JavaScript syntax.

  2. Calls get_horoscope but the function is defined as getHoroscope.

  3. Passes the entire parsed object into the function, while it should pass args.sign.

  4. Uses json.dumps (Python) instead of JSON.stringify, but actually the API expects a plain object, not a string.

  5. Refers to input_list which doesn’t exist — the array is named input.

response.output.forEach((item) => {
  if (item.type === "function_call") {
    if (item.name === "get_horoscope") {
      const args = JSON.parse(item.arguments || "{}");
      const horoscope = getHoroscope(args.sign);

      input.push({
        type: "function_call_output",
        call_id: item.call_id,
        output: { horoscope }, // plain object, not JSON.stringify
      });
    }
  }
});

Would be great if the docs could be updated so developers don’t copy/paste broken code :folded_hands: