Is it possible to get the Assistants API to generate images

I’m trying to use the assistance API to generate images in the threads. So far I haven’t had any success with this. The only thing that I get out is a pretty good description of the image that I asked it to create, but no image whatsoever. I wanted to see if anyone else has been able to figure this out.


You can use an assistant to generate images but not as a tool like Code Interpreter but rather as a function that will pass a prompt for an image to the image generation endpoint and return the image back to the assistant’s run.


This is how I display the image file generated by the assistant:

messages = client.beta.threads.messages.list(thread_id)
for message in reversed(
for message_content in message.content:

if hasattr(message_content, “image_file”):
file_id = message_content.image_file.file_id
resp = client.files.with_raw_response.retrieve_content(file_id)
if resp.status_code == 200:
image_data = BytesIO(resp.content)
img =

So, if message.content has the attribute “image_file”, we can retrieve the id of the file generated by the assistant.