
openai
#10067
tool_call_response_error
An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. Ensure there are response messages for all tool_call_ids.
This error has been identified and solved.
Reason
The 400 error you are encountering is due to the OpenAI API's requirement that any assistant message containing tool_calls
must be followed by corresponding tool messages that respond to each tool_call_id
. In your case, the error indicates that there are tool_call_ids
(e.g., call_IgY8KfYmUElkJC2OkNmF44z3
) that do not have the necessary response messages associated with them. This mismatch between the tool calls and the responses is causing the API to reject the request as invalid.
Solution
To fix the 400 error caused by the absence of response messages for tool_call_ids
, you need to ensure that each tool call is followed by the appropriate response message. Here are the key steps to resolve this issue:
Ensure that for every tool_call_id
in your assistant message, there is a corresponding tool message that responds to that specific tool_call_id
.
Verify that all tool calls have matching response messages.
Reconstruct the conversation flow to include the necessary tool responses.
Update your code to generate or include these response messages accurately.
By aligning your tool calls with the required response messages, you can prevent the API from returning a 400 error.
Suggested Links
https://community.openai.com/t/getting-400-response-with-already-working-code/509212
https://github.com/langchain-ai/langchain/discussions/23733
https://forum.bubble.io/t/open-ai-api-http-400-error-payload/268017
https://community.openai.com/t/formatting-assistant-messages-after-tool-function-calls-in-gpt-conversations/535360
https://community.openai.com/t/opena-ai-bad-request-error-400/666947
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://github.com/langchain-ai/langchainjs/issues/6622
https://github.com/Nutlope/aicommits/issues/137