Next.Js createChatComplete api throwing request error

I want to use gpt-3.5-turbo model for which the API in nodeJS seems to be createChatCompletion which throws request error in nextJS. Im able to get the response with textdavinci model in creatCompletion API. Not sure since if the API is not working since it is in beta.

My code:

// Prepare the messages for the chat conversation
const inputs = [
{
role: “system”,
content: “You are an AI assistant who is helpful, creative, clever, and very friendly.”,
},
{ role: “user”, content: userInput },
];
try {
const response = await openai.createChatCompletion({
model: “gpt-3.5-turbo”,
messages: inputs, // Use the messages parameter
max_tokens: 20,
temperature: 0.7,
});
res.status(200).json({
result: response.data.choices[0].message.content
});

Try this code but replace GPT4 with gpt turbo. This is for a next.js API request.

Full guide here.

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

export default async function handler(req, res) {

  const configuration = new Configuration({
    apiKey: "<INSERT-API-KEY-HERE>",
  });

  const openai = new OpenAIApi(configuration);

  const response = await openai.createChatCompletion({
    model: "gpt-4",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "Who won the world series in 2020?" },
      { role: "assistant", content: "The Los Angeles Dodgers." },
      { role: "user", content: "Where was it played?" },
    ],
    max_tokens: 50,
    n: 1,
    stop: null,
    temperature: 1,
  });

  r

I’m getting the same issue — OpenAI’s API returns a 200, but an error is thrown nonetheless. Did you ever figure out a solution?

Turned out that messages was missing the proper data. All is well now.