TypeError: openai.createImage is not a function

I’m having trouble debugging this error. I’m able successfully make a request to openai.createCompletion(), but openai.createImage() gives me the TypeError mentioned in the title of this post.

    const imageResponse = await fetch("/api/imagegen", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      body: JSON.stringify({ title: title }),


import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
const openai = new OpenAIApi(configuration);

export default async function (req, res) {
    const image = await openai.createImage({
        prompt: generatePrompt(req.body.title),
        n: 1,
        size: "1024x1024",

    res.status(200).json({ result: image.data.choices[0].text });

function generatePrompt(title) {
    return `${title} in the style of high-quality food photography`;

Solved: I had to upgrade openai to 3.1.0

1 Like

I have upgraded to 3.1.0 but still the same error

This is still a problem on 3.2.1.

const response = await openai.createImage({

TypeError: openai.createImage is not a function

Getting typeerror and i am in version 4.2.0.

Has your error been resolve?
if yes kindly give the solution

See the API docs. For openai 4.x:

import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const image = await openai.images.generate({ prompt: "A cute baby sea otter" });


now i am getting this
BadRequestError: Billing hard limit has been reached

You can adjust your usage limits here.