#Nothing happens I dont get a response

1 messages · Page 1 of 1 (latest)

daring lintel
#

Hey Im using groq instead of open ai i should get a repsonse but nothing happens. Whats the issue here

torn barn
#

if that doesn't solve anything / you dont find anything please provide the try block so i can see if its a issue in there. Shouldn't have any senestive things.

daring lintel
torn barn
#

thx

daring lintel
#

I have tried changing the keys but it still doesnt work

torn barn
#

hmm

torn barn
#

that will help us more finding a solution

daring lintel
#

try {
const response = await openai.chat.completions.create({
model: process.env.AI_MODEL,
messages: [
{
role: "user",
content: prompt,
},
],
});

console.log("AI response:");
console.log(response.choices[0].message.content);

} catch (error) {
if (error.status === 401 || error.status === 403) {
console.error(
"Authentication error: Check your AI_KEY and make sure it’s valid."
);
} else if (error.status >= 500) {
console.error(
"AI provider error: Something went wrong on the provider side. Try again shortly."
);
} else {
console.error(
"Unexpected error:",
error.message || error
);
}
}

theres already one in here

torn barn
#

ahh

#

thx

#

hold on

#

let me try it on my own machine ill get back to you soon

daring lintel
#

ok

torn barn
# daring lintel ok

okay try moving the try block inside a async function example: async function main(){Your try block here } and call main function after (you can name it anything)

daring lintel
#

like this?

torn barn
#

yh

#

and make sure to call it after

#

let me know if that fixes it

daring lintel
#

nope still nothing

torn barn
#

hm

torn barn
# daring lintel nope still nothing

lets take a differnet approach at the top of your file above everything add a console.log saying something like FILE STARTED! and before calling the main function add a console.log saying going to Main FUNCTION

#

this way we can see if it even gets to calling the main function in the first place or gets stuck some where else

#

you can also try adding console.log("AI_KEY set?", Boolean(process.env.AI_KEY));
console.log("AI_URL:", process.env.AI_URL);
console.log("AI_MODEL:", process.env.AI_MODEL); before the try catch in the main function

#

If AI_KEY set? is false or AI_URL/AI_MODEL is undefined, that’s why the request never succeeds.

daring lintel
#

ok i added the logs i still dont get any response in console what could be the issue

torn barn
daring lintel
#

nope

torn barn
#

wow thats a weird problem

torn barn
# daring lintel nope

do you know how run the file manually instead of using run button like using the built in terminial in Scrimba?

daring lintel
#

no

torn barn
#

run 'node index.js' in the terminal and go back to see in console to see if anything logs

#

last thing i suggest doing is add a random thing at the top like wqklfhkfqlkfq, and if you still dont get any outputs in the console that means the file itself is not running somehow

#

as you said the api/ai things are correct, atleast with what i reviewed i think it is a Scrimba issue. since the file doesn't even run like you said.

daring lintel
#

heres the result im getting

torn barn
#

also if your goal is groq? why dont you use the offical link not by openrouter..

torn barn
#

the solution i posted before didnt work for me so i removed it.

daring lintel
#

whats the official link ?

torn barn
#

then a api key from the offical dev page, you can go to the website console.groq.com to create a account and get a api key and it should.. work

daring lintel
#

im using open router right now