Socket
Socket
Sign inDemoInstall

chatgpt-io

Package Overview
Dependencies
12
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chatgpt-io

ChatGPT Client API, Blazing Fast, without using browser


Version published
Weekly downloads
17
increased by54.55%
Maintainers
1
Install size
2.36 MB
Created
Weekly downloads
 

Readme

Source

Update 21-JAN-2023

We have implemented support for pro accounts. [C# Version][Python Version]

For support join [Discord]

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

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

A simple Node.js module for interacting with the ChatGPT without using any Browser.

import chatGPT from "chatgpt-io";

(async () => {
  let bot = new chatGPT("<SESSION_TOKEN>");
  await bot.waitForReady();

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

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>");

// or if your accounts is pro
let bot = new chatGPT("<SESSION_TOKEN>", {
    proAccount: true
});

Before making any requests to the API, you should wait for the bot instance to be ready by calling the waitForReady method. This ensures that the connection to the API has been established and any necessary setup has been completed.

await bot.waitForReady();

Once the bot instance is ready, 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.

ES6 Update

This library is now using ES6 syntax and is intended to be used with the "module" type in your package.json file. This means that you will need to update your package.json file to include the following:

{
  "type": "module"
}

In addition, you will need to change any instances of "require" to "import" in your code. For example, instead of:

const chatGPT = require("chatgpt-io");

You will now use:

import chatGPT from "chatgpt-io";

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; // default = "default"
  reconnection: boolean; // default = true
  forceNew: boolean; // default = false
  logLevel: LogLevel; // default = Info
  bypassNode: string; // default = "https://gpt.pawan.krd"
  proAccount: boolean; // default = false
}
LogLevel = {
  Trace = 0,
  Debug = 1,
  Info = 2,
  Warning = 3,
  Error = 4
}
waitForReady(): Promise<void>

Waits for the chatGPT instance to be ready to make requests to the API. Returns a promise that resolves when the instance is ready.

ask(message: string, conversationId?: 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.

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";

(async function () {
  let bot = new chatGPT("<SESSION_TOKEN>");
  await bot.waitForReady();

  // 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);
})();

Event example(Alpha)

import chatGPT from "chatgpt-io";

(async function () {
  let bot = new chatGPT("<SESSION_TOKEN>");

  bot.onConnected = async () => {
    await bot.waitForReady();
    // default conversation
    let response = await bot.ask("Hello?");
    console.log(response);
  };
})();

Server Example

In examples/server.js you can find an example of how to use the chatgpt-io module to create a simple Fastify server that can be used to send messages to ChatGPT.

Run the server by setting the CHATGPT_SESSION_TOKEN environment variable to your ChatGPT API session token and running the following command:

node examples/server.js

You can also set the port with the CHATGPT_PORT environment variable. The default port is 3000.

To send a message to the server, make a POST request to http://localhost:<port>/ask with the following JSON body:

{
  "message": "Hello?",
  "conversation_id": "any-unique-string"
}

A standalone version of this API server can be found at chatgpt-io-api.

Keywords

FAQs

Last updated on 28 Jan 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc