Hey there, Ive been trying to get a chrome extension to work with openai/api. Just for this part im stuck on getting it to find my api key?
Heres the error im recieving from openai:
"error": {
"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), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
And here is what my auth looks like THIS KEY IS DELETED ITS JUST AN EXAMPLE
// openai.js
// Function to send user message to OpenAI API and receive assistant's reply
async function getAssistantReply(userMessage) {
const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer THISISMYKEY'
},
body: JSON.stringify({
prompt: userMessage,
max_tokens: 50, // Adjust as needed
temperature: 0.6 // Adjust as needed
})
});
const data = await response.json();
return data.choices[0].text.trim();
}