Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chatgpt-io

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatgpt-io

ChatGPT Client API, Blazing Fast, without using browser

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by800%
Maintainers
1
Weekly downloads
 
Created
Source

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
  • sessionToken (string): Your ChatGPT API session token.
  • options (object):
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
  • message (string): The message to send to the API.
  • conversationId (string, optional): The ID of the conversation to send the message to. If not provided, the default conversation will be used.
  • parentId (string, optional): The ID of the parent message. If not provided, the message will not have a parent.

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
  • callback (function): The callback function to call with the API's response as it is received.
  • message (string): The message to send to the API.
  • conversationId (string, optional): The ID of the conversation to send the message to. If not provided, the default conversation will be used.
  • parentId (string, optional): The ID of the parent message. If not provided, the message will not have a parent.

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.

Keywords

FAQs

Package last updated on 29 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc