How to use JSON mode in Next.js for a chat completion?

I am using npm openai package in Next.js to create a chat completion but its not accepting “response_format” as I want the reponse to be in JSON.
Kindly check code attached for the route.
Thanks!
`import { NextResponse } from “next/server”;
import OpenAI from “openai”;

const openai = new OpenAI({
apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY,
});

export async function POST(request: Request) {
const { ingredients } = await request.json();

if (!ingredients)
return NextResponse.json({ message: “Ingredients not found.” });

const chatCompletion = await openai.chat.completions.create({
messages: [
{
role: “system”,
content: You are a skilled chef known for creating recipes. Given a list of ingredients, your task is to formulate two distinct recipes. Each recipe should include the following keys: 'title' for the title of the recipe, 'description' for the description, 'steps' for the step-by-step guide to preparation and cooking, 'time' for the total time required in minutes, 'ingredients' for the list of ingredients, 'cuisine' for the cuisine of the recipe, and 'calories' for the estimated calorie count per serving,
},
{
role: “user”,
content: Please produce 2 unique recipe for the following ingredients: ${ingredients},
},
],
model: “gpt-3.5-turbo-1106”,
});

return NextResponse.json(chatCompletion);
}
`

You need to add:

response_format: { type: "json_object" }

So working with your code it would be:

const chatCompletion = await openai.chat.completions.create({
messages: [
{
role: "system",
content: `You are a skilled chef known for creating recipes. Given a list of ingredients, your task is to formulate two distinct recipes. Each recipe should include the following keys: 'title' for the title of the recipe, 'description' for the description, 'steps' for the step-by-step guide to preparation and cooking, 'time' for the total time required in minutes, 'ingredients' for the list of ingredients, 'cuisine' for the cuisine of the recipe, and 'calories' for the estimated calorie count per serving` ,
},
{
role: "user",
content: `Please produce 2 unique recipe for the following ingredients: ${ingredients}` ,
},
],
model: "gpt-3.5-turbo-1106",
response_format: { type: "json_object" }
});