Assistant API ... Save png image issue

Hi All,

I’m probably just doing something wrong, but I’m trying to save and display a png image generated from the assistant api. I use retrieve_content which gives me the image content as a string. When I try to encode to bytes I get UnicodeEncodeError: ‘latin-1’ codec can’t encode character ‘\ufffd’ in position 0: ordinal not in range(256) … I can see the header says PNG and it looks ok as far as I can tell. Just some unicode errors.


This appears to be fixed in a more recent version. With the latest python SDK you can save the PNG like so:

image_file_id = "file-abc-123"
image_file = openai.files.content(image_file_id)
with open("plot.png", "wb") as f:

Excellent. Thanks for responding!