Error: Request failed with status code 404 GPT-3.5-TURBO

The following code is giving me a 404 error. From my understanding a 404 in this case is that I am calling an incorrect endpoint except I am using the openai library so I don’t believe I am making an error in the api url aspect.

import { NextResponse } from 'next/server';
import { Configuration, OpenAIApi } from 'openai';
const configuration = new Configuration({
    apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

export async function POST(request) {
    try {
        const { description } = await request.json();

        if (!description || description === '') {
            return new Response('Please send your prompt', { status: 400 });
        }

        const aiResult = await openai.createCompletion({
            model: 'gpt-3.5-turbo',
            prompt: `This is my prompt say something back`,
            temperature: 0,
            max_tokens: 2048,
            top_p: 1,
            frequency_penalty: 0.0,
            presence_penalty: 0.0,
        });

        return NextResponse.json({text: aiResult});
    } catch(error) {
        console.error(error);
        return new Response('An error occurred', { status: 500 });
    }
}

1 Like

The issue is you are using model “gpt-3.5-turbo” and it will not work with “openai.createCompletion({”. If you want to use model “gpt-3.5-turbo” then you need to use “openai.createChatCompletion({”.
Ex.
openai.createChatCompletion({
model:‘gpt-3.5-turbo’,
messages: conversationHistory,
temperature:0,
top_p:1,
frequency_penalty:0,
presence_penalty:0,
max_tokens:360
});

1 Like