Yeah, images can be tricky. Hoping you get it sorted.
me and @raymonddavey are almost positive there’s an issue on open AI’s end. either the endpoint is broken, or something vital is missing from the docs. we tinkered and tinkered last night, but nothing worked in the end. hopefully we hear something from the devs about it before too long
You can specify the response_format as ‘b64_json’ to get the generated image returned as base64 data
const response = await openai.createImage({
prompt: prompt,
n: 1,
size: "256x256",
response_format: "b64_json",
});
const base64 = response.data.data[0].b64_json;
This base64 data can then be used to create a buffer which can be passed into the API request
const buffer = Buffer.from(base64, "base64");
// Set a `name` that ends with .png so that the API knows it's a PNG image
buffer.name = "image.png";
const response = await openai.createImageVariation(buffer, 1, "256x256", "b64_json");
base64Data = response.data.data[0].b64_json;
Full code to create a new image and a variation of the generated image:
const response = await openai.createImage({
prompt: "digital artwork of a robotic lion wearing a crown",
n: 1,
size: "256x256",
response_format: "b64_json",
});
const image = response.data.data[0].b64_json;
// This is the Buffer object that contains the generated image base64
const buffer = Buffer.from(image, "base64");
// Set a `name` that ends with .png so that the API knows it's a PNG image
buffer.name = "image.png";
const response = await openai.createImageVariation(buffer, 1, "256x256", "b64_json");
const variation = response.data.data[0].b64_json;
Hope this helps ![]()
I wish more people here would reply like you @swiftrees with “working code” (and API responses and error messages) instead of opinions and theories without working code and detailed error messages from the API.
Well done!
Please stick around and keep posting working solutions in code!
![]()
