TypeError: openai.createChatCompletion is not a function

I got this error tried many things to resolve it but can’t please help me
I checked API key its working in python code
this is the code:

const { Configuration, OpenAIApi } = require("openai");

const configuration = () =>{ return Configuration (
  {
    organization: "",
  apikey:"API_key"
  }
);
};

const openai = () =>{ return OpenAIApi(configuration);};

async function callApi() {
  const response = await openai.createChatCompletion({
    model: "gpt-3.5-turbo",
    prompt: "Say this is a test.",
    max_tokens: 7,
    temperature: 0,
  });

  console.log(response.data.choices[0].text)
}
callApi();

Are you using openai v4? v4 had a number of significant changes.

See the migration guide: v3 to v4 Migration Guide · openai/openai-node · Discussion #217 · GitHub

2 Likes