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 🙏

© 2024 – Pkg Stats / Ryan Hefner

chatgpt-io-v2

v1.1.2-alpha.3

Published

ChatGPT Client API, Blazing Fast, without using browser

Downloads

14

Readme

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

let bot = new chatGPT("<SESSION_TOKEN>");
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.