This is a Typescript starter project for using the Open AI API to build a Node app.
In this example app, you enter the name of a product and it outputs a product review, formatted in a very specific way in markdown. You can use this as a starting point to build purpose-built generative API functionality.
Technologies used:
-
If you don’t have Node.js installed, install it from here
-
Clone this repository
-
Navigate into the project directory
cd openai-api-next-starter
- Install the requirements
npm install
- Make a copy of the example environment variables file
cp .env.example .env
-
Add your API key to the newly created
.env
file -
Run the app
npm run dev
You should now be able to access the app at http://localhost:3000. Happy hacking.
I've run this successfully on Vercel and I'd recommend them for any Next.js (they invented Next and their DX is the best!)
Included in the repo is a vercel.json file. You need this to set a higher serverless function timeout since the Open AI API takes about 20-30 seconds to compute. Please note that Hobby accounts will always timeout at 10s so you need to upgrade to a pro account for this to work. Totally worth it.