I’m a trying to make a post request, where I sent an image with a mask (png from a local folder), but get the error 415. I now that 415 means an error with the media-type, but I can see I’m doing it wrong.
This is the image:
This is the doc I’m looking at: OpenAI API
This is my code/function to make the request to Dall-E:
async function generateImage() {
try {
const imageUrl = "https://api.openai.com/v1/images/edits";
const requestBody = JSON.stringify({
image: "/test/test.png",
prompt: "Make a background of bananas",
n: 1,
size: "512x512",
});
const response = await fetch(imageUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer MY SECRET CODE`,
},
body: requestBody,
});
if (response.ok) {
const responseData = await response.json();
setResultImage(responseData.resultImage);
console.log("response", responseData);
stageRef.current = responseData.resultImage;
} else {
console.log("Failed to generate image", response.status);
}
} catch (error) {
console.log(error);
}
}
Can anyone see what is wrong?
I have asked ChatGPT as well, but nothing helped…