How to pass function call outputs while streaming using Responses API?

Indeed processing the stream fully and queuing up the function calls does the job, thank you!

The code below does the job:

let functionCalls: ResponseFunctionToolCall[] = [];

do {
  // Process text messages.
  ({ assistantMessage, functionCalls } =
    await this.streamResponse(input, {
      assistantMessage,
      conversation,
      toolChoice: this.getToolChoice(someData),
      tools,
      user,
    }));

  // Process function calls.
  input = [];

  for (const functionCall of functionCalls) {
    const res = await this.processFunctionCall(tarotReading, functionCall);

    someData = res.someData;
    input = [...input, ...res.input];
  }
} while (functionCalls.length);
1 Like