How to solve? Response {type: 'cors', url: 'https://api.openai.com/v1/chat/completions'

I’m trying to make a call to ChatGPT API. Here’s the code:

const response = await fetch(‘https://api.openai.com/v1/chat/completions’, {
headers: {
‘Content-Type’: ‘application/json’,
Authorization: 'Bearer ’ + ‘api’,
},
method: ‘POST’,
body: JSON.stringify({
model: ‘gpt-3.5-turbo’,
messages: [
{
role: ‘user’,
content: ‘Hola’,
},
],
}),
})

And this is the response I get:

body : ReadableStream
bodyUsed: false
headers
: Headers {}
ok : true
redirected: false
status: 200
statusText: “”
type: “cors”
url : “https://api.openai.com/v1/chat/completions

Any idea on how to fix this?

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 OpenAI Platform",