Returning tool / function results over OpenAI API

I am trying to implement tool use through the OpenAI endpoints. I get a 400 error (request contains an invalid argument), but I think it’s about passing back the function call (role: assistant, toolCalls message)

    "tools": [
        {
            "type": "function",
            "function": {
                "name": "mul",
                "description": "Multiply 2 numbers",
                "parameters": {
                    "type": "object",
                    "properties": {"x": {"type": "number"}, "y": {"type": "number"}},
                    "required": ["x", "y"],
                },
            },
        }
    ],
    "model": "models/gemini-2.0-flash-exp",
    "max_completion_tokens": 500,
    "messages": [
        {"role": "system", "content": "Use tools for all calculations where possible."},
        {"role": "user", "content": "what is two times three"},
        {
            "role": "assistant",
            "toolCalls": [
                {
                    "id": "0",
                    "type": "function",
                    "function": {"arguments": "{'x': 2, 'y': 3}", "name": "mul"},
                }
            ],
        },
        {"role": "tool", "tool_call_id": "0", "name": "mul", "content": "6.0000"},
    ],
}

I’m getting the toolCall from the first model response, but how should I format it and the result of the function for the next turn?

Another comment is that the OpenAI client expects “tool_calls” argument, but this endpoint is returning “toolCalls” so these aren’t being properly parsed by the client into the appropriate OpenAI client objects.

Yes, I encountered the same problem and had to implement a temporary workaround.