Running your exact code from Step 2 fails–choice[0] is not defined. Seems it’s trying to return data from that array before the promise is fulfilled? The exact same request correctly runs in the browser console:

fetch(‘https://api.openai.com/v1/chat/completions’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’: `Bearer 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`,
},
body: JSON.stringify({
model: ‘gpt-3.5-turbo’,
messages: [{ role: ‘user’, content: ‘Tell me a joke’ }]
})
}).then(response => {
return response.json()
}).then(data=>{
console.log(data[‘choices’][0].message.content)
})