Logo

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 or image_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 the content 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 type text or image_url.

  • Avoid base64 encoded images in content: Do not include base64 encoded image data directly in the content field. Instead, use the image_url type with a valid URL.

  • Construct valid image URLs: If using images, construct a valid image_url by prefixing the base64 encoded string with data: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.

Original Error Message

Raw

Invalid chat format. Content must be either text or image URL type.

Original Error Message

Raw

Invalid chat format. Content must be either text or image URL type.

© 2024 Portkey, Inc. All rights reserved

HIPAA

COMPLIANT

GDPR

Transform Your AI app prototypes to be production-ready

Talk to us →