OpenAI NodeJS

OpenAI NodeJS

A non-official OpenAI API wrapper for node.

Getting Started

Installation

If you have npm installed, start using openai-nodejs with the following commands.

npm install openai-nodejs

Usage

openai-nodejs follows the latest maintenance LTS version of Node.

Example - Complete the phrase "My name is Bond"

const OpenAI = require('openai-nodejs');
const client = new OpenAI('YOUR_API_KEY');

var prompt = 'My name is Bond';
client.complete(prompt, {stop: ['\n', '"'], temperature: 0})
.then(completion => {
    console.log(`Result: ${prompt}${completion.choices[0].text}`);
})
.catch(console.error);

The likely answer will be ", James Bond!"

If you want to see more examples, please check our documentation.

Documentation

You can check the full API reference here.

Note: Some API parameter descriptions adopted from OpenAI's API Reference. If you use the Official OpenAI's API docs as your primary reference, be aware that this library has some differences compared to it.

License

MIT