Dall-e images.edit no longer working with Cloud Functions - Worked Previously

Hello,
I’m experiencing an issue with the images.edit endpoint of dall-e-2 within my Firebase Cloud Functions environment. My integration, which has been working flawlessly for several months, suddenly started failing overnight.
Someone else on the forum also noticed that change and had a similar issue though their solution didn’t work for me.

The error I’m consistently receiving is:
“unsupported mimetype (‘application/octet-stream’)”

This occurs when attempting to send a PNG image (created from a Buffer and File objects) to the images.edit endpoint from our Firebase Cloud Function. The same code works correctly in our local development environment

const filename = 'myimage.png'; 
const mimeType = 'image/png';  
                          
const file = new File([buffer], filename, { type: mimeType });

const result = await openai.images.edit({
  model: 'dall-e-2',
  image: file,
  prompt: prompt,
  n: 1,
  size: '1024x1024',
});

The cloud function environment correctly logs the File object’s type as image/png, indicating the issue lies in how this is being transmitted or interpreted by the images.edit endpoint specifically from this environment.

Would anyone have any idea how to resolve this issue if it is actually possible to do so ? thank you for your help !

Hi @valere1,

I recently faced a very similar issue while integrating the DALL·E images.edit endpoint with GPT-4o in a cloud-based project using the EHUD++ framework. The error you’re getting – unsupported mimetype (‘application/octet-stream’) – usually means that the file’s MIME type isn’t being passed correctly through the cloud function layer.

Here are some suggestions that might help:

  1. Ensure the MIME type is explicitly defined as ‘image/png’ not only in the File object but also in the Content-Type header of your request.

  2. Wrap the buffer inside a Blob first, then create the File to ensure type propagation:

const blob = new Blob([buffer], { type: ‘image/png’ });
const file = new File([blob], ‘myimage.png’, { type: ‘image/png’ });

  1. Try using FormData with the proper headers instead of passing the file directly:

const formData = new FormData();
formData.append(“image”, file);

const result = await fetch(“https://api.openai.com/v1/images/edit”, {
method: “POST”,
headers: {
Authorization: Bearer ${process.env.OPENAI_API_KEY},
},
body: formData,
});

  1. Log the headers on the Firebase side to see what’s actually being sent. Sometimes Cloud Functions alter the request body and headers:

functions.logger.info(req.headers);

Let me know if that helps! We’re working with image pipelines and smart rendering with GPT-4o too, and would love to see your integration back up and running.

– Nicholas, Harmonia AI Project

1 Like

Hi @webpause22
Thank you very much for your help, It works, I’ve used your 3rd solution and it works perfectly !

I don’t know why it works when using the “fetch” method but anyway, I’m glad it works, I was out of solution.

Thank you ! All the best for your project !

1 Like