Welcome to the community!
A 401 errors means it couldn’t authenticate. You need to send the API key in the header as a bearer…
This page might be helpful? They have a working example for nodejs…
Hope this helps.
ETA:
const headers = {
'Authorization': `Bearer ${process.env.OPENAI_SECRET_KEY}`,
};