Nice to meet you.
Recently, the image.edit API stopped working.
Has anyone experienced a similar issue or knows the cause?
import io
import PIL as pil # pip3 install Pillow
import openai
print('OpenAI Version:', openai.__version__)
image = pil.Image.open('unit_test/data_in/black_cat_rgb.png')
binary_data = None
with io.BytesIO() as byte_stream:
image.save(byte_stream, format='PNG')
binary_data = byte_stream.getvalue()
client = openai.OpenAI()
client.images.edit(
image=binary_data,
model='dall-e-2',
prompt='A cute baby sea otter wearing a beret',
)
OpenAI Version: 1.75.0
---------------------------------------------------------------------------
BadRequestError Traceback (most recent call last)
Cell In[3], line 16
13 binary_data = byte_stream.getvalue() # ăă€ăăȘććŸ
15 client = openai.OpenAI()
---> 16 client.images.edit(
17 image=binary_data,
18 model='dall-e-2',
19 prompt='A cute baby sea otter wearing a beret',
20 )
File ~/workspace/orcas_proj/venv/lib/python3.12/site-packages/openai/resources/images.py:195, in Images.edit(self, image, prompt, mask, model, n, response_format, size, user, extra_headers, extra_query, extra_body, timeout)
191 # It should be noted that the actual Content-Type header that will be
192 # sent to the server will contain a `boundary` parameter, e.g.
193 # multipart/form-data; boundary=---abc--
194 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
--> 195 return self._post(
196 "/images/edits",
197 body=maybe_transform(body, image_edit_params.ImageEditParams),
198 files=files,
199 options=make_request_options(
200 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
201 ),
202 cast_to=ImagesResponse,
203 )
File ~/workspace/orcas_proj/venv/lib/python3.12/site-packages/openai/_base_client.py:1276, in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls)
1262 def post(
1263 self,
1264 path: str,
(...) 1271 stream_cls: type[_StreamT] | None = None,
1272 ) -> ResponseT | _StreamT:
1273 opts = FinalRequestOptions.construct(
1274 method="post", url=path, json_data=body, files=to_httpx_files(files), **options
1275 )
-> 1276 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File ~/workspace/orcas_proj/venv/lib/python3.12/site-packages/openai/_base_client.py:949, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
946 else:
947 retries_taken = 0
--> 949 return self._request(
950 cast_to=cast_to,
951 options=options,
952 stream=stream,
953 stream_cls=stream_cls,
954 retries_taken=retries_taken,
955 )
File ~/workspace/orcas_proj/venv/lib/python3.12/site-packages/openai/_base_client.py:1057, in SyncAPIClient._request(self, cast_to, options, retries_taken, stream, stream_cls)
1054 err.response.read()
1056 log.debug("Re-raising status error")
-> 1057 raise self._make_status_error_from_response(err.response) from None
1059 return self._process_response(
1060 cast_to=cast_to,
1061 options=options,
(...) 1065 retries_taken=retries_taken,
1066 )
BadRequestError: Error code: 400 - {'error': {'message': "Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.", 'type': 'invalid_request_error', 'param': 'image', 'code': 'unsupported_file_mimetype'}}