Home

Awesome

For support join [Discord]

chatgpt-io - Unofficial API client for ChatGPT [Discord]

NPM NPM GitHub issues GitHub forks GitHub stars GitHub license Discord server

Check the new Google Bard Chatbot!

A simple NPM package for interacting with the ChatGPT without a browser.

import chatGPT from "chatgpt-io";

let bot = new chatGPT("<SESSION_TOKEN>");
let response = await bot.ask("Hello?");
console.log(response);

Table of Contents

How the new method working without a browser?

The new method operates without a browser by utilizing a server that has implemented bypass methods to function as a proxy. The library sends requests to the server, which then redirects the request to ChatGPT while bypassing Cloudflare and other bot detection measures. The server then returns the ChatGPT response, ensuring that the method remains effective even if ChatGPT implements changes to prevent bot usage. Our servers are continuously updated to maintain their bypass capabilities.

Installation

To install the package, run the following command:

npm install chatgpt-io

Usage

To use the package, require it in your code and create a new instance of the ChatGPT class, passing in your ChatGPT API session token as an argument.

import ChatGPT from "chatgpt-io";

let bot = new ChatGPT("<SESSION_TOKEN>");

// set the model manually, for plus accounts
let bot = new ChatGPT("<SESSION_TOKEN>", {
	model: "text-davinci-002-render-sha",
});

Then you can send a message to the API using the ask method. This method takes a message string as its first argument and an optional conversation ID as its second argument. If a conversation ID is not provided, the default conversation will be used.

let response = await bot.ask("Hello?");
console.log(response);

let response2 = await bot.ask("Hello?", "any-unique-string");
console.log(response2);

The ask method returns a promise that resolves with the API's response to the message.

API Reference

ChatGPT class

constructor(sessionToken: string, options: object)

Creates a new instance of the ChatGPT class.

Parameters
options = {
	name?: string;  // name of the instance (default: "chatgpt-io")
	logLevel?: LogLevel;  // log level (default: LogLevel.Info)
	bypassNode?: string; // bypass node url (default: https://api.pawan.krd)
	model?: string; // model to use (default: text-davinci-002-render-sha)
	configsDir?: string;  // directory to save configs (default: ./configs)
	saveInterval?: number;  // interval to save configs (default: 1000 * 60 * 5)
}
LogLevel = {  // log levels
  Trace = 0,
  Debug = 1,
  Info = 2, // default
  Warning = 3,
  Error = 4
}

ask(prompt: string, id: string = "default", parentId?: string): Promise<string>

Sends a message to the API and returns a promise that resolves with the API's response.

Parameters

askStream(callback: (arg0: string) => void, prompt: string, id: string = "default", parentId?: string): Promise<string>

Sends a message to the API and returns a promise that resolves with the API's response. This method is similar to ask, but it will call the callback function with the API's response as it is received instead of waiting for the entire response to be received.

Parameters

Example

Here is an example of how to use the chatgpt-io module to send a message to the API and log the response:

import ChatGPT from "chatgpt-io";

let bot = new ChatGPT("<SESSION_TOKEN>");

// default conversation
let response = await bot.ask("Hello?");
console.log(response);

// specific conversation
let response2 = await bot.ask("Hello?", "any-unique-string");
console.log(response2);

// stream response
await bot.askStream((response) => {
	console.log(response);
}, "Hello?");

// stream response with conversation
await bot.askStream(
	(response) => {
		console.log(response);
	},
	"Hello?",
	"any-unique-string",
);

License

This project is licensed under the MIT License - see the LICENSE file for details.