OpenAI tool calling returns inconsistent response

I am using GPT-4o for my tool calling agent and tool calling response is very inconsistent. Sometime, after a tool call, finish_reason=‘stop’ which is wrong as it should be ‘tool_calls’ and sometime it gives me correct finish_reason=‘tool_calls’. I read the docs but I am not sure if I am missing something in the documentation.

Welcome to the dev forum @hasnain.khan

Are you using tool_choice param?

Existing Topic:

1 Like

I tried both with and without tool_choice='auto' but in both case, response is consistent.

Can you confirm the exact finish reason?

In case of tool calling, sometime finish reason is stop and sometime finish reason is tool_calls.

I did some testing on my end and was unable to reproduce the issue. If you have the code and chat completion request IDs please share them here.