[Fixed] OpenAI API error: "OpenAIApi is not a constructor" – Node.js

by
Ali Hasan
chatgpt-api node.js openai-api

Quick Fix: Adapt the code to use OpenAI NodeJS SDK v4 since v3 is no longer supported. Use ‘new OpenAI({ apiKey: process.env.OPENAI_API_KEY, })’ for initialization and ‘await openai.chat.completions.create(…)’ instead of ‘await openai.createChatCompletion(…)’ for chat completion.

Q&A

What is a major change if you use version 4 of the OpenAI NodeJS SDK?

Use OpenAI instead of OpenAIApi to initiate a new client.

In the latest OpenAI NodeJS SDK version, how do you create a chat completion?

Use chat.completions.create instead of createChatCompletion.

Video Explanation:

The following video, titled "How to Fix OpenAI API Request Error - Exceeding Current Quota ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

My #1 Recommendation: ➡️➡️➡️ https://wow.link/No1Recommend DONT CLICK THIS: https://wow.link/ytw1 OpenAI Links: OpenAI Pricing ...