
openai
#10074
input_format_error
Invalid chat format. Content must be either text or image URL type.
This error has been identified and solved.
Reason
The 400 Bad Request
error with the message "Invalid chat format. Content blocks are expected to be either text or image_url type" in the OpenAI API is likely occurring because the request payload does not conform to the expected format. Here are the key reasons:
The payload may contain content blocks that are not correctly formatted as either
text
orimage_url
types.The
content
field might include data that does not match the specified types, such as base64 encoded image data which is not allowed in thecontent
field.
Solution
To resolve the 400 Bad Request
error with the message "Invalid chat format. Content blocks are expected to be either text or image_url type," you need to ensure your request payload is correctly formatted. Here are the key steps to fix this issue:
Use the correct content types: Ensure that each content block in the
messages
field is either of typetext
orimage_url
.Avoid base64 encoded images in content: Do not include base64 encoded image data directly in the
content
field. Instead, use theimage_url
type with a valid URL.Construct valid image URLs: If using images, construct a valid
image_url
by prefixing the base64 encoded string withdata:image/png;base64,
or similar, but ensure this is used as a URL and not as base64 data within the content block.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 are formatted correctly and avoid the 400 Bad Request
error.
Suggested Links
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://community.openai.com/t/how-do-i-use-the-new-json-mode/475890
https://community.openai.com/t/error-sending-base64-image-data-in-api-request-to-gpt-4-vision-model/495864
https://community.openai.com/t/intermittent-error-an-unexpected-error-occurred-error-code-400-error-message-this-model-does-not-support-specifying-dimensions-type-invalid-request-error-param-none-code-none/955807
https://platform.openai.com/docs/guides/text-generation
https://github.com/openai/openai-python/issues/1483
https://community.openai.com/t/getting-400-response-with-already-working-code/509212
https://community.openai.com/t/uploading-images-to-the-chatgpt-api/985494