I’m trying to implement ChatGPT bot into my personal website and running into an issue. I am trying to connect the API key to my codebase without hardcoding it and it’s giving me a few issues. One is a certificate issue, another is an API not connecting issue. I have a .env with API_KEY=myAPIkey Below is the main code:
import { config } from “dotenv”
config()
import OpenAI from ‘openai’;
const openai = new OpenAI({
apiKey: process.env.API_KEY // This is also the default, can be omitted
});
const chatCompletion = await openai.chat.completions.create({
model: “gpt-3.5-turbo”,
messages: [{“role”: “user”, “content”: “Hello!”}],
}).then(res => {
console.log(res)
})
console.log(process.env.API_KEY)
I’m also getting the following: “message”: "You didn’t provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY)