openai.createImage is not a function

import OpenAI from ‘openai’;

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

const generateImage = async (req, res) => {
try {
const response = await openai.createImage({
model: “dall-e-3”,
prompt: “a white siamese cat”,
n: 1,
size: “1024x1024”,
response_format: “url”,
});
image_url = response.data.data[0].url;

res.status(200).json({
  success: true,
  data: imageUrl, // Corrected variable name
});

} catch (error) {
if (error.response) {
console.log(error.response.status);
console.log(error.response.data);
} else {
console.log(error.message);
}
res.status(400).json({
success: false,
error: ‘The image could not be generated’,
});
}
};

export { generateImage };

You are using v3 code. See Reference page for update

v4 code

const image = await openai.images.generate({ 
    model: "dall-e-3", 
    prompt: "A cute baby sea otter" 
});

This needs updating on the official documentation, then… https://platform.openai.com/docs/guides/images/usage?context=node&lang=node.js

const response = await openai.createImage({
  model: "dall-e-3",
  prompt: "a white siamese cat",
  n: 1,
  size: "1024x1024",
});
image_url = response.data.data[0].url;
1 Like