This example shows how to connect a simple <form> to the OpenAI Chat API in the browser.
Install the dependencies:
npm installCreate an OpenAI Account and get your Secret API Key.
Create a file named .env in the root of the project and add your API Key to it. You can use the env.example file to help you:
cp env.example .envNow edit .env and replace the ... with your API key.
Bundle the code and start a server:
npm startYou can now try the app at http://localhost:1234.
Do NOT put this code on the public internet, since it would expose your Secret API KEY. It is fine to run it locally, however.