# (Need help) Discord Bot using Open AI API - node.js

**URL:** <https://community.openai.com/t/need-help-discord-bot-using-open-ai-api-node-js/41546>\
**Category:** API\
**Created:** [January 20, 2023, 3:06pm UTC](https://community.openai.com/t/need-help-discord-bot-using-open-ai-api-node-js/41546 "2023-01-20T15:06:33Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![i-technology](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/i-technology/32/21608_2.png) [@i-technology](https://community.openai.com/u/i-technology)\
**Post date:** [January 20, 2023, 7:49pm UTC](https://community.openai.com/t/need-help-discord-bot-using-open-ai-api-node-js/41546/3 "2023-01-20T19:49:27Z")

</div>

No clue why you are getting an error, it would probably be easier to debug with vanilla JS

Here is a low tech example:

```auto
async function openAi(apiKey, method, data) {
  let requestOptions = {
    method : 'POST',
    headers : {
	  'Content-Type' : 'application/json',
      'Authorization': `Bearer ${apiKey}`,
    },
    body: JSON.stringify(data)
  };
  
  return await fetch(`https://api.openai.com/v1/${method}`, requestOptions).then((response) => response.json());
}

let request = {
  "model" : "text-davinci-003",
  "prompt" : "<input text>",
  "temperature": 0,
  "max_tokens" : 1000
}

let result = await openAi(localStorage.getItem('myApiKey'), 'completions', request);
console.log(result.choices[0].text);

```

PS: didn’t test this code, i ripped it out of one of my abstraction layers and edited it for easy understanding …milage may vary ^^

---

_[View the full topic](https://community.openai.com/t/need-help-discord-bot-using-open-ai-api-node-js/41546)._
