API_KEY Problem

I am making a chat bot with ChatGpt, but i am getting an error where it tells me that i did not provide an API KEY but i did, i cant seem to find a solution or where did i go wrong in my code, so anything helps, thank you
No description
No description
9 Replies
Tenkes
Tenkes6mo ago
Line 23. it should be headers not header
lajkmi.
lajkmi.OP6mo ago
Still gives the same error message
Tenkes
Tenkes6mo ago
Well that shouldn't happen. Try refreshing, restarting server etc?
lajkmi.
lajkmi.OP6mo ago
yea tried all that, i am confused as hell xDDD
ἔρως
ἔρως6mo ago
why don't you use the openai npm package? https://platform.openai.com/docs/api-reference/introduction
Tenkes
Tenkes6mo ago
Wait are you trying to access that page directly lol? Like you typed URL in your browser? I don't get why are you getting error message like that
ἔρως
ἔρως6mo ago
he is, i just noticed that now
Tenkes
Tenkes6mo ago
Yeah well @lajkmi. you cannot access it like that. You have to fetch it like you already did and then log data to the console Also not sure if you put your API_KEY there just for demo/debugging purposes but just in case I'll warn you not to do that since everyone will be able to access it. Instead you should create ".env" file where you will store it something like this:
API_KEY=my_super_secret_api_key
API_KEY=my_super_secret_api_key
And then access it through that API_KEY variable
lajkmi.
lajkmi.OP6mo ago
Yea i fixed it thank you for the input 🙂
Want results from more Discord servers?
Add your server