TypeError from OpenAiAPI: openai.createCompletion is not a function

I’m trying to run a script and keep getting this in the terminal “TypeError: openai.createCompletion is not a function” I’m trying to use the OpenAiAPI but having some issues with it. Has anyone experienced this TypeError?

I’m using: model this text-model: “text-davinci-002”,
This is how I import it: const OpenAIAPI = require(“openai”);
Node -v: v16.20.2
OpenAi -v: ^4.11.1

text-davinci-002 is a quite old model, indicating that you either found some old guide, or asked ChatGPT how to write some code.

The OpenAI library version 4 has significant changes that you have to read about, and you will likely want to be using model gpt-3.5-turbo for typical chatbot applications which employs the ChatCompletion method.

1 Like

Welcome to the community!

I would recommend you update your version of the OpenAI API.

You can find more information here:

Good day, I am working with Dall E for image creation. Are there migration docs for image creation too and not just text completion. I am getting an erro that says “Error creating image: Request failed with status code 401”

You can see the new method naming for image creations.

  • createImageimages.generate

For actual use, obtaining the url or image data back from the model, you’ll have to read further and code further.

Ok thank you very much, can i get a link to the updated documentation so that i can work better.

I would really appreciate a link to the new documentation. thank you.

here you go

So this meansi would replace the instances made for chat completions in the documentation with images.generate then.

I have taken a look at the openai repository and I am trying to use the v4 for image completion but I am facing issues. The chat samples I am seeing are for chat completion, I need to an API sample thanks