Next.js Discord

Discord Forum

Help me please

Unanswered
torquiii posted this in #help-forum
Open in Discord
Original message was deleted.

103 Replies

Original message was deleted
Ok, we got half an error telling us absolutely nothing except that a server-side error occurred on what ever server you are trying to send a request to. What should we do now?
Lapland Longspur
Context?
I use API With Open Ai
@torquiii Click to see attachment
Alright. We need to see the code for /app/api/conversation/ then
Give me another error
No, the code that handles the /api/conversation route
404
What?
Dwarf Crocodile
i think he got 404 error code
@torquiii Click to see attachment
You weren't supposed to change it
Look
Give me another error
Dwarf Crocodile
@torquiii can we see /api/conversation route's code?
You have a Next.js app. This app consists of code. The route you are trying to request (/api/conversation) has code as well to handle the request you make to it. I want to see that code
Wait
I can't really ready any of that
Can you just copy and paste the code?
Dwarf Crocodile
its really? please use discord on desktop...
that camera photo...
Dwarf Crocodile
and we really cant see the routes
@ncls. Can you just copy and paste the code?
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.apiKey) {
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('[conversation_ERROR]', error)
return new NextResponse('Internal error', { status: 500 })
}
}
** Page 2**
Dwarf Crocodile
you need use /api/conversation. if you get error code then openai not configured , or you got internal error. (see the code)
Wait a second
@ncls. What does your console say? (Not the browser one)
@torquiii Click to see attachment
Dwarf Crocodile
/app/api/conversation replace to /api/conversation
@torquiii Click to see attachment
Not the browser one
@ncls. Wait a second
Okii bro
@Dwarf Crocodile /app/api/conversation replace to /api/conversation
Gave the same error as the first 500
@torquiii Gave the same error as the first 500
Dwarf Crocodile
yes , see the code.
if the code got error you get error code 500
what the console says?
in browser
we need more information
@torquiii Click to see attachment
Show us the console output of the console you started the Next.js app with. So the one you typed npm run dev into
I use yarn
Then that
Dwarf Crocodile
Man.
But there should be something inside your non-browser console
Dwarf Crocodile
Its.
I see the problem in axios
Most likely starting with "[conversation_ERROR]"
@torquiii I see the problem in axios
The problem is not axios
axios is working fine
@torquiii Click to see attachment
I went on the hunt to find your console. Looks like you are rate limited form the API
So you made too many requests in a short time
Dwarf Crocodile
you have try catch. In the try part have a bad code. We cant know wheres the problem. Its not problem of routing. We need to know what the output the response.data.choices[0].message.
yape.
its the try failed to running jumped to catch and you got response data to error code 500.
Look AxiosError
@torquiii Look AxiosError
No, you have another console open. Show that one
On the right side of your console, there are two windows. The top one is your actual console and it probably says "429"
@torquiii So what is the solution now
Dwarf Crocodile
ohh man..
my soul is broken now
first of all check in part of "try" check all variable, wheres is the error
wheres wrong
if you put the code github
i will help you
@ncls. Most likely starting with "`[conversation_ERROR]`"
Yes
@torquiii Yes
...
@Dwarf Crocodile if you put the code github
Wait a minute, what's your name in github
You are rate limited from the OpenAI API. Case closed, someone close this thread please
@torquiii Wait a minute, what's your name in github
Dwarf Crocodile
go to the dm manxd
What do you mean
@torquiii What do you mean
You made too many requests to their API
So they temporarily locked you out
You have to wait until they let you make requests again
There's no fix you can do from your side besides waiting
Because of this there is a 500 error
Yes
Because your try catch fails and therefore returns a 500 error
As you told it to
Dwarf Crocodile
yes
@ncls. You made too many requests to their API
I think yes now I used a lot of API
@torquiii I think yes now I used a lot of API
Then try again later
If you use an account gmail new And I got a new API Will the problem open?
No, because your API key stays the same and that's the thing the API identifies you with
Dwarf Crocodile
+1
Just wait. Eat something, watch a movie, whatever and then try again
Silver Marten
+ 1
Dwarf Crocodile
and have to chance you flooding the request to the api
Silver Marten
pretty good solution if you ask me
what is true /api/conversation or /app/api/conversation
/api/conversation
Thank you my friend for you and your time zorty💪👌
Dwarf Crocodile
you're welcome man. have a nice day.