DEV Community

Joshua Akan-Etuk
Joshua Akan-Etuk

Posted on • Originally published at joshuaakanetuk.com on

How To Use Open AI API with Node.js

ChatGPT has become one of the most popular web applications of all-time. The firm, OpenAI, that created ChatGPT actually has an API that allow access to the same models that ChatGPT uses and more. This article will demonstrate quickstart usage for OpenAI's API for Node.js.

This requires a credit card, but you are provided $5 credits before you are change

  1. First you'll need to create an API account via OpenAI's platform. It's free to create.

  2. Create an API key and save it securely somewhere as it is required to make requests to OpenAI.

  3. Create a Nodejs project. Run npm init if you like.

  4. Install the openai package:

npm install openai@^4.0.0
Enter fullscreen mode Exit fullscreen mode

or

yarn install openai@^4.0.0
Enter fullscreen mode Exit fullscreen mode
  1. Create a index.js and paste the following code (sourced from OpenAI docs):
import OpenAI from "openai";

const openai = new OpenAI({
  organization: 'YOUR_ORG_ID',
});
Enter fullscreen mode Exit fullscreen mode

You are now ready to make other requests!

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay