# Using API with node.js and p5

**URL:** <https://discourse.processing.org/t/using-api-with-node-js-and-p5/37410>\
**Category:** Libraries\
**Created:** [June 8, 2022, 8:42pm UTC](https://discourse.processing.org/t/using-api-with-node-js-and-p5/37410 "2022-06-08T20:42:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omri](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@Omri](https://discourse.processing.org/u/Omri)\
**Post date:** [June 8, 2022, 8:42pm UTC](https://discourse.processing.org/t/using-api-with-node-js-and-p5/37410/1 "2022-06-08T20:42:48Z")

</div>

hey, there is a website I’d like to use his API in a P5 sketch I’m doing.  
The API looks like that:

```auto
const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
  model: "text-davinci-002",
  prompt: "Decide whether a Tweet's sentiment is positive, neutral, or negative.\n\nTweet: \"I loved the new Batman movie!\"\nSentiment:",
  temperature: 0,
  max_tokens: 60,
  top_p: 1,
  frequency_penalty: 0.5,
  presence_penalty: 0,
});

```

I tried looking up an answer but couldn’t find one.  
does anyone have any idea?  
thanks 🙂

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 9, 2022, 2:53pm UTC](https://discourse.processing.org/t/using-api-with-node-js-and-p5/37410/2 "2022-06-09T14:53:57Z")

</div>

Hi,

And why you’re not just installing the [The OpenAI Node.js library](https://www.npmjs.com/package/openai) ?  
ie: npm install openai

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Omri](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@Omri](https://discourse.processing.org/u/Omri)\
**Post date:** [June 10, 2022, 9:42am UTC](https://discourse.processing.org/t/using-api-with-node-js-and-p5/37410/3 "2022-06-10T09:42:14Z")

</div>

Thank! I had no idea that exist…  
How do I use that in the P5?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 10, 2022, 11:42am UTC](https://discourse.processing.org/t/using-api-with-node-js-and-p5/37410/4 "2022-06-10T11:42:36Z")

</div>

Hi,

P5 is client-side and node server-side.  
Guess you should implement some server side openai interface which you can call from your p5 scripts.  
In general it should work that way, but I’ve not done yet and therefore you’ve to try it on your own … 🙂

Cheers  
— mnse
