/openai-api-next-starter

OpenAI Next.js starter project

Primary LanguageTypeScript

OpenAI API - Next.js Starter Project

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:

Setup

  1. If you don’t have Node.js installed, install it from here

  2. Clone this repository

  3. Navigate into the project directory

cd openai-api-next-starter
  1. Install the requirements
npm install
  1. Make a copy of the example environment variables file
cp .env.example .env
  1. Add your API key to the newly created .env file

  2. Run the app

npm run dev

You should now be able to access the app at http://localhost:3000. Happy hacking.

Deployment

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.