'Endpoint not found' when calling client.images.edit for editing Images.

Describe the bug

I am using openai edit function to edit my input image but I am getting an error.

Python Version: 3.11.8
OpenAI API version: 1.75.0
OS: windows

To Reproduce

from openai import OpenAI client = OpenAI(api_key=API_KEY) response = client.images.edit( image=open(“input_img.jpg”, “rb”), # must be square PNG with transparency mask=open(“mask.png”, “rb”), # must match size, show area to edit prompt=“Convert this into a mosaic artwork made from curved stained-glass tiles.”, n=1, size=“1024x1024” ) image_url = response.data[0].url print(f"Edited Mosaic Image: {image_url}")

The above code throws the error below:

NotFoundError Traceback (most recent call last)
Cell In[26], line 5
1 from openai import OpenAI
3 client = OpenAI(api_key=“[api-key]
----> 5 response = client.images.edit(
6 image=open(“input_img.jpg”, “rb”), # must be square PNG with transparency
7 mask=open(“mask.png”, “rb”), # must match size, show area to edit
8 prompt"Convert this into a mosaic artwork made from curved stained-glass tiles.“,
9 n=1,
10 size=“1024x1024”
11 )
13 image_url = response.data[0].url
14 print(f"Edited Mosaic Image: {image_url}”)

File c:\Users\Dev\AppData\Local\Programs\Python\Python311\Lib\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 c:\Users\Dev\AppData\Local\Programs\Python\Python311\Lib\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 c:\Users\Dev\AppData\Local\Programs\Python\Python311\Lib\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 c:\Users\Dev\AppData\Local\Programs\Python\Python311\Lib\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 )

NotFoundError: Error code: 404 - {‘error’: {‘message’: ‘Endpoint not found’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

OS

Windows

Python version

3.11.8

Library version

1.75.0

Your code is a little wrong, but even when corrected I still get an error, I’ve let OpenAI know.

#corrected code
from openai import OpenAI
client = OpenAI()

response = client.images.edit(
    model="dall-e-2",
    image=open("input_img.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="A sunlit indoor lounge area with a pool containing a flamingo",
    n=1,
    size="1024x1024",
)

print(response.data[0].url)

Not a model I’ve used before, so there could be depreciations or other stuff going on, hopefully find out soon.

1 Like