# How to use openai API using javascript?

**URL:** <https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808>\
**Category:** API\
**Created:** [October 11, 2022, 1:50pm UTC](https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808 "2022-10-11T13:50:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtuluve](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jtuluve/32/12304_2.png) [@jtuluve](https://community.openai.com/u/jtuluve)\
**Post date:** [October 11, 2022, 1:50pm UTC](https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808/1 "2022-10-11T13:50:13Z")

</div>

I want to use openai API but without node js. Is it possible? If yes, how can I do it? Thank You

---

<div class="post-metadata">

**Author:** ![josephfrusetta](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/josephfrusetta/32/379335_2.png) [@josephfrusetta](https://community.openai.com/u/josephfrusetta)\
**Post date:** [October 12, 2022, 7:52pm UTC](https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808/2 "2022-10-12T19:52:17Z")

</div>

Hi jtuluve. It’s definitely possible, but I would recommend using node js as there are many more resources out there should you ever get stuck.

Here’s [an example of someone using NextJS and React](https://harishgarg.com/writing/how-to-build-a-serverless-gpt-3-powered-using-nextjs-react/) to build their application.

---

<div class="post-metadata">

**Author:** ![nick.yang](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick.yang](https://community.openai.com/u/nick.yang)\
**Post date:** [October 13, 2022, 1:34pm UTC](https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808/3 "2022-10-13T13:34:35Z")

</div>

Hi Jtuluve,

This is my prompt that I tested in the playground and Codex gave me a 95% done code.

```auto
<!-- create a html web page that has input area for user to enter their requirement and API key to call OpenAI Codex to generate code for them.

The resposne from OpenAI Codex should be shown in a textarea on the web page.

Only HTML and Javascript can be used in the web page.-->

<!DOCTYPE html>

```

Go through contnet in the below link then you will understand how to use it.

> **[OpenAI API](https://beta.openai.com/docs/guides/code)**
>
> An API for accessing new AI models developed by OpenAI

---

<div class="post-metadata">

**Author:** ![VivacityDesign](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/vivacitydesign/32/230492_2.png) [@VivacityDesign](https://community.openai.com/u/VivacityDesign)\
**Post date:** [October 31, 2023, 7:02pm UTC](https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808/4 "2023-10-31T19:02:16Z")

</div>

If i understand well, you want to create a simple chatbot based on chatgpt using pure client javascript?  
In case, see my github repository. Since the forum editor does not let me add links, look for the repository ‘VivacityGTP-Online’ by MisterCoder74

this also has context memory. if you change the model to ghatgpt-3.5turbo-16k you will have about 17000 chars for your interactions.  
Please notice that you will have to insert your api key in this section:

headers: {  
‘Content-Type’: ‘application/json’,  
‘Authorization’: ‘Bearer _yourapikeyhere_’  
},

---

<div class="post-metadata">

**Author:** ![EricGT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ericgt/32/20571_2.png) [@EricGT](https://community.openai.com/u/EricGT)\
**Post date:** [December 21, 2023, 8:10am UTC](https://community.openai.com/t/how-to-use-openai-api-using-javascript/21808/5 "2023-12-21T08:10:01Z")

</div>

Closed on December 21, 2023, 8:10am UTC


