npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chatgpt-api-client

v1.0.5

Published

JS client for ChatGPT API

Readme

JS Client for official OpenAI completions API with AI models that ChatGPT uses.

This package is available for both uses borwser oriented Single Page Applications as well as for Common.JS use.

Install

npm install chatgpt-api-client or yarn add chatgpt-api-client

Ensure you're using node >= 14 to prevent compatibility issues with obsolete node versions

Usage

You have to pass your API key for authentification. Visit the page https://platform.openai.com/account/api-keys to retrieve the API Key you'll use in your requests. Supposed in the below demo that the key is stored in the environment file.

import { ChatGPTApi } from "chatgpt-api-client";

async function try() {
    const api = new ChatGPTApi({ apiKey: process.env.OPENAI_API_KEY });
    const response = await api.sendMessage({ prompt: "Hi! How is the weather today?" });
    console.info(response);
}

For users who belong to multiple organizations, you can pass a this property to specify which organization is used for an API request.

const api = new ChatGPTApi({ apiKey: process.env.OPENAI_API_KEY, organization: "custom-org" });

You can specify which AI model will be used in the processing of your requests.

const response = await api.sendMessage({ model: "model-id-0", prompt: "Hi! How is the weather today?" });

text-davinci-003 is the default model that is specified in case of non-mentioned model property.

There are a bit of parameters to pass in the sendMessage function namely the max of tokens, temperature and number of completions.

const response = await api.sendMessage({ 
        prompt: "Hi! How is the weather today?", //The prompt(s) to generate completions for
        model: "text-davinci-003", //ID of the model to use
        max_tokens: 500, //The maximum number of tokens to generate in the completion
        temperature: 0, //What sampling temperature to use, between 0 and 2, Default is 1
        nCompeletions: 3 //How many completions to generate for each prompt. Default is 1
    });
const api = new ChatGPTApi({ apiKey: process.env.OPENAI_API_KEY });
//Retrieve the list of available OpenAI models
let models = await api.getModels();

Usage with Promise return

The previous examples were made with Async/Await calls through asynchronos promise. We could explicitly handle the return of Promise Object.

api.sendMessage({ prompt: "Hello! this is a test" }).then((response) => {
    //Proceed with success
    console.info("Response data", response);
}, error => {
    //An error has occured
    console.error("Error", error);
});

For Common.JS usage

const { ChatGPTApi } = require("chatgpt-api-client");

Github repository

If you have any contribution request, feature or if you found a bug or any issue please report them to this github repository

License

ISC © https://opensource.org/

Author

Brahim Slimani