Error 500 with gpt-3.5-turbo second day in a row

Hi,

I’m getting from gpt-3.5-turbo error 500 for the second day in a row. At the same time, I can see on Openai status monitor that all services should be operational. Does anyone have similar issues? I have contacted Openai Help bot, but haven’t got any help.

Error: 500: OpenAI API error: The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID 37b1bdf62430adf46a53058e48db1481 in your email.)

If you post your code you used to make your API call, we can help you identify what the problem is, @deepscreener

:slight_smile:

Thanks for questioning my own code! The code worked fine before I changed stop: “” to stop:“\n”. Now I changed it back to stop: “” and it works again. By documentation both are fine. Weird!

2 Likes

In 95 percent of the issues posted here, it’s generally a developer error.

It’s beta code, as you know, so it’s best to test and test again.

:slight_smile:

1 Like

Thanks, indeed it was the “stop” key that caused the error on the server side.
The error handling on the OpenAI side should be clearer :confused:

1 Like

I have been encountering same error 500 from this morning : this is route.ts file in chat folder for chatting with gpt-3.5-turbo :

import { auth } from "@clerk/nextjs";
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(req: Request) {
    try {
        const { userId } = auth();
        const body = await req.json();
        const { messages } = body;

        if (!userId) {
            return new NextResponse("Unauthorized", { status: 401 });

        }

        if (!configuration) {
            return new NextResponse("OpenAI API key not configured", { status: 500})
        }

         if (!messages) {
            return new NextResponse("Messages are Required", { status: 400 })
         }
        
        const response = await openai.createChatCompletion({
            model: "gpt-3.5-turbo",
            messages
            });
            return NextResponse.json(response.data.choices[0].message);

    } catch (error) {
        console.log("[CHAT_ERROR]", error);
        return new NextResponse("Internal server error", { status: 500})
    }
}

If anyone can help please reply…

In your code you are returning error 500 if the API is not correctly configured. is the API key valid if you print it to console as a test?

Yes the api key is showing in the console.[quote=“Foxabilo, post:7, topic:90658, full:true”]
In your code you are returning error 500 if the API is not correctly configured. is the API key valid if you print it to console as a test?
[/quote]

I think what he is saying, is that you are coding any captured error to be “500” - and also returning number that look like, but aren’t, connection errors.

You’d want to get the actual http error and message, and compare if it’s the real error 500:

500 - The server had an error while processing your request Cause: Issue on our servers.
Solution: Retry your request after a brief wait and contact us if the issue persists. Check the status page.

https://platform.openai.com/docs/guides/error-codes/api-errors

Guys I tried!

Solution: Retry your request after a brief wait and contact us if the issue persists.

but cannot get rid of this error:500. May be i’m not up to date! :thinking:

import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";
import OpenAI from "openai";

const configuration = {
  apiKey: process.env.OPENAI_API_KEY,
};

const openai = new OpenAI({ apiKey: configuration.apiKey });

export async function POST(req: Request) {
  try {
    const { userId } = auth();
    const body = await req.json();
    const { messages } = body;

    if (!userId) {
      return new NextResponse("Unauthorized", { status: 401 });
    }

    if (!configuration.apiKey) {
      return new NextResponse("OPenAI API key not configured", { status: 500 });
    }

    if (!messages) {
      return new NextResponse("Message is required", { status: 400 });
    }

    const chatCompletion = await openai.chat.completions.create({
      model: "gpt-3.5-turbo",
      messages: [messages],
    });

    return NextResponse.json(chatCompletion.choices[0].message);
  } catch (error) {
    console.log("[CONVERSATION_ERROR]", error);
    return new NextResponse("Internal Server Error", { status: 500 });
  }
}