OK, so casting may be part of your problem.
OpenAI requires you to cast things as Any when you pass images. It is a Typescript specific issue.
Here are two code snippets.
Like I said, they are untested and they are from a course I am working on.
But the key thing with this slide is that Typescript is the same as Node but it requires the “Any” casting
Snippet 1: (This is for an edit with a mask and refers back to a file)
const response = await openai.createImageEdit(
fs.createReadStream(“sunlit_lounge.png”) as any,
fs.createReadStream(“mask.png”) as any,
“A sunlit indoor lounge area with a pool containing a flamingo”,
1,
“1024x1024”
);
Here is snippet 2 - (It uses binary data - it is for a variation image - but the way you need to recast the buffer to a new object with type any and then you also need to name the new object is important. If you don’t use the name, it also tends to fail)
// This is the Buffer object that contains your image data
const buffer: Buffer = [your image data];
// Cast the buffer to any
so that we can set the name
property
const file: any = buffer;
// Set a name
that ends with .png so that the API knows it’s a PNG image
file.name = “image.png”;
const response = await openai.createImageVariation(
file,
1,
“1024x1024”
);
Hope it helps