
openai
#10551
value_mismatch_error
Invalid value: expected 'function' but received an incompatible input. Please check the input value.
This error has been identified and solved.
Reason
The error you're encountering, specifically the "Invalid value: 'tool_call'. Value must be 'function'" with a 400 status code, is likely due to an incorrect configuration or misuse of the API parameters.
Here are the key reasons for this error:
Incorrect Role Specification: The OpenAI API requires that messages with the role 'tool' must be a response to a preceding message with 'tool_calls' or the correct role specification. Using 'tool_call' instead of 'function' violates this requirement[4").
API Documentation Mismatch: There might be discrepancies between the code you're using and the latest API documentation. For example, OpenAI's documentation may specify 'function' instead of 'tool' or 'tool_call', and using the wrong term can lead to this error.
Sequence of Messages: The error can also occur if the sequence of messages in your API requests is not maintained correctly, particularly when dealing with chat or conversation contexts.
These issues indicate a misalignment between your code and the expected API parameters or sequence.
Solution
To fix the "Invalid value: 'tool_call'. Value must be 'function'" error with a 400 status code in the OpenAI API, you need to ensure the correct usage of API parameters and roles. Here are the steps to resolve the issue:
Check and correct the role specification in your API requests to use 'function' instead of 'tool_call'.
Ensure that the sequence of messages in your API requests is correct and follows the specified roles.
Verify that your code aligns with the latest OpenAI API documentation.
Key corrections:
Use 'function' instead of 'tool_call'.
Maintain the correct sequence of messages.
Align your code with the latest API documentation.
Suggested Links
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://community.openai.com/t/content-is-required-property-error-400/486260
https://community.openai.com/t/getting-400-response-with-already-working-code/509212
https://github.com/run-llama/llama_index/issues/13715
https://community.openai.com/t/request-failed-with-status-code-400/39242
https://cdn.openai.com/spec/model-spec-2024-05-08.html
https://forum.bubble.io/t/openai-api-error-http-400/263917
https://arize.com/blog-course/mastering-openai-api-tips-and-tricks/