
openai
#10073
input_format_error
Invalid chat format. Content must be either text or image URL type.
This error has been identified and solved.
Reason
The error "Invalid chat format. Content blocks are expected to be either text or image_url type" with a 400 status code in the OpenAI API is likely due to the following reasons:
Incorrect Payload Structure: The API request payload might not be formatted correctly, specifically the
messages
field. It may contain invalid or unsupported content types other thantext
orimage_url
.Unsupported Content Types: The API does not support the type of content you are trying to send, such as base64 encoded images, which may not be correctly recognized or handled by the API.
Non-Compliant Content Blocks: The content blocks within the
messages
array may not adhere to the expected format, which requires each block to be either a text message or an image URL.
Solution
To fix the "Invalid chat format. Content must be either text or image URL type" error in the OpenAI API, you need to ensure your request payload is correctly formatted. Here are the key steps:
Use Supported Content Types: Ensure that each content block in the
messages
array is either of typetext
orimage_url
.Correct Payload Structure: Verify that the
messages
field is an array of content objects, each containing a validrole
andcontent
field.Image URLs Instead of Base64: Use image URLs instead of base64 encoded images, as base64 images may not be supported in the current API version.
Check API Documentation: Refer to the OpenAI API documentation to ensure your payload structure matches the expected format.
By adhering to these guidelines, you can ensure your API requests comply with the required format and avoid the 400 error.