Should parallel function calling results be returned in the same order as in the response from the model?

Hi,

I’m working with parallel function calling, and I want to confirm a detail about returning function outputs after executing the tool calls.

When the model returns multiple tool calls (e.g., in parallel), am I required to return the tool results in the exact same order as the tool calls were provided in the original response?

(I now that for Gemini at least it is the case, but I could not find anything about it in the OpenAI documentation)

Thank you

Function returns can be returned async and out-of-order. They must be in the same “return” API call though.

That is why parallel functions require the same ID as the function that was emitted (or currently, you are allowed to fabricate your own IDs when managing chat), to put them back in the order that the AI called them in, for AI understanding. The API endpoint refuses messages that don’t have an ID pairing between tool_call and the immediate tool role return.

The AI doesn’t actually experience these IDs (where an index indeed could be useful); it just sees the same order returned as was output into the “parallel function wrapper” tool (unless someone forgets this re-sort need when coding more API backend over there).

You can try it out: have the AI tweet, “AI is cool” along with a tweet “Just Married”. Then ask it which failed when you return “{status 500 server error}” for one, and simply “success” for the other, with and without shuffling.