openAI image creation migration to V4 for Node.js developers

For anyone who is a javascript developer looking to migrate v4 on DALL.E, your migration docs are here for you. Read well.

A setup like this would be like this

const openai = new Openai({
  apiKey: process.env.OPENAI_API_KEY,

const main = async (req, res) => {
  try {
    const response = await openai.images.generate({
      prompt: "a flying astronaut",
      n: 1,
      size: "256x256",

    const image_url =[0].url;
    res.json({ data: image_url });
  } catch (error) {
    // res.status(500).json({ error: "An error occurred" });
    console.error("Error creating image:", error.message);


Make sure you have free credits or purchased some.