OpenAI API for Image Generation is returning error “Returning Error : Request failed with status code 400”
Below is my code :
const { Configuration, OpenAIApi } = require(“openai”);
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const generateImage = async (req, res) => {
try {
console.log("OPENAI API KEY : ", process.env.OPENAI_API_KEY);
const response = await openai.createImage({
model: "image-alpha-001",
data: {
prompt: "Polar Bear on Ice Skates",
n: 1,
size: "512x512",
},
});
const imageURL = response.data.data[0].url;
console.log(imageURL);
res.status(200).json({
status: "success",
imageURL: imageURL,
});
} catch (error) {
console.log("Returning Error : ", error.message);
res.status(500).json({
status: "error",
message: error.message,
});
}
};
module.exports = { generateImage };
can’t found proper solution, Please Help me.