DallE image edit API with error: invalid character '-' in numeric literal

I am using exactly the same demo code here, but got below error:

---------------------------------------------------------------------------
BadRequestError                           Traceback (most recent call last)
Cell In[6], line 1
----> 1 response = client.images.edit(
      2   model="dall-e-2",
      3   image=open("sunlit_lounge.png", "rb"),
      4   mask=open("mask.png", "rb"),
      5   prompt="A sunlit indoor lounge area with a pool containing a flamingo",
      6   n=1,
      7   size="1024x1024"
      8 )
      9 image_url = response.data[0].url
     10 print(image_url)

File ~/Library/Python/3.9/lib/python/site-packages/openai/resources/images.py:184, in Images.edit(self, image, prompt, mask, model, n, response_format, size, user, extra_headers, extra_query, extra_body, timeout)
    179 if files:
    180     # It should be noted that the actual Content-Type header that will be
    181     # sent to the server will contain a `boundary` parameter, e.g.
    182     # multipart/form-data; boundary=---abc--
    183     extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
--> 184 return self._post(
    185     "/images/edits",
    186     body=maybe_transform(body, image_edit_params.ImageEditParams),
    187     files=files,
    188     options=make_request_options(
...
   (...)
    987     stream_cls=stream_cls,
    988 )

BadRequestError: error, status code: 400, message: invalid character '-' in numeric literal

My code:

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

Could you take a look?

note that the original code snippet has an incomplete bracket after edit. I removed in my code

Are you using latest OpenAI library? It changes quite frequently.

Same error on multiple tries or was it a one-off?

I am using openai-1.17.0.

Yes, same error on multiple tries, in various env and machines.

1 Like

Also tried different image, prompt, removing some of the optional args. Same error

1 Like
response = client.images.edit(**(**

Yeah, that error in the sample makes me think there’s something else wrong?

Might be a bug. No time to test here, but thanks for sharing.

Hopefully someone else can take a look.

At first glance, though, I don’t see anything.

ETA: Could by python version too? I’d check that next…

Thanks. Tested on both python 3.9, 3.11.7, same error
Yes, I was also thinking could be edit(xx(xx or edit({xx something. Please help to correct it.

The doubling of the function’s starting quotes is what is problematic in the example.

Your example code:

from openai import OpenAI
client = OpenAI()

response = client.images.edit(
    prompt="A sunlit indoor lounge area with a pool containing a flamingo",
    image=open("sunlit_lounge.png", "rb"),
    mask=open("mask.png", "rb"),
    response_format="url",  # or b64_json
)
image_url = response.data[0].url
print(image_url)

Your example images (PNG, not WebP):

(the forum is now jpegging uploads, a new undesired behavior)



Your response is a https URL, revealing:


Links:

View post on imgur.com
1 Like

Thanks for checking.

It turned out to be some error from my side that causing the error. If I directly use openai’s api, the issue is gone.

1 Like

It’s configurable :slight_smile: not new

2 Likes

However: what you see above is me clearing the images, and then pasting links to an imgur.com hosted image. The link to original file is lost with the function needed is lost.

The forum downloads, ingests, recompresses, redistributes, attempts to own, the externally-hosted files. That’s playing fast and loose with “it’s on the internet, so it must be free” copyright law.

Also very optional

Link rot is not a theoretical problem it destroys the value of the internet

I do agree though that we could label this better, at least on hover or click

2 Likes