
azure-openai
#10044
input_format_error
Invalid image data: the provided image data is not correctly formatted in base64.
This error has been identified and solved.
Reason
The 400 status error in the Azure OpenAI API when dealing with base64 image data can be attributed to several factors:
Invalid Payload Structure
The payload may not be correctly formatted, particularly the content
keys, which need to be objects rather than strings. For example, the content
field might be expected to be an array of content objects with specific types (e.g., text
or image_url
)[4'.
Content Type and Format
The base64 encoded image may not be properly structured or may not match the expected format. For instance, the API might expect an image_url
type with a specific base64 format, but the provided data does not conform to this expectation.
Exceeding Data Payload Size
The base64 encoded image data might exceed the maximum size allowed by the OpenAI API, leading to the server rejecting the request.
Content Filter and Policy Violations
The image data could be triggering content filters or violating Azure OpenAI's content management policies, causing the request to be filtered out.
Incorrect API Endpoint or Version
Issues related to the specific API endpoint or version being used can also lead to errors. The endpoint or version might not support base64 image data as expected, or there could be changes in the API that are not accounted for in the current implementation.
Header and Authentication Issues
Incorrect headers, such as an invalid Content-Type
or improperly configured Authorization
field, can also result in a 400 error.
Solution
To resolve the 400 status error in the Azure OpenAI API when dealing with base64 image data, you should take the following steps:
Ensure that the payload is correctly formatted, with the content
field structured as an object rather than a string. Verify that the base64 encoded image data conforms to the expected format and does not exceed the maximum allowed size.
Here are some key actions to consider:
Verify the payload structure, especially the
content
keys.Check that the base64 encoded image matches the expected format.
Ensure the image data does not exceed the maximum size limit.
Review the image data for compliance with content filters and policies.
Confirm that the API endpoint and version support base64 image data.
Validate the request headers, including the
Content-Type
andAuthorization
fields.
Suggested Links
https://portkey.ai/error-library/prompt-error-10016
https://community.openai.com/t/error-sending-base64-image-data-in-api-request-to-gpt-4-vision-model/495864
https://learn.microsoft.com/en-us/answers/questions/1479386/azure-openai-api-calling-issue
https://community.openai.com/t/gpt-4-vision-preview-400-invalid-base64-image-url/679812
https://learn.microsoft.com/en-us/answers/questions/1462206/why-resp-api-returns-error-400-the-request-has-an
https://community.openai.com/t/how-can-i-write-a-post-request-for-azure-openai-that-uses-structured-output/898569
https://portkey.ai/error-library/unsupported-image-error-10015
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/structured-outputs?tabs=rest