Today I decided to use the chatGpt API for a mini project in Js, everything was “Ok”, until I went to use console.log() to see if it was reaching the server, I came across the 401 error. is giving this problem is line 14 and in my line 14 has the following code:
await fetch("https://api.openai.com/v1/completions",
await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers:{
Accept:"application/json", "Content-Type": "applications/json",
Authorization: "Bearer" + KEY,
},
body: JSON.stringify({
model: "text-davinci-003",
prompt: pergunta,
max_tokens: 2048,
temperature: 2,
})
});
how can i solve this error ?