On December 11th, OpenAI added Cloudflare protections that make it more difficult to access the unofficial API.
This package works to access ChatGPT pretty consistently, even after OpenAI added Cloudflare protections. To circumvent these protections, we've added a **fully automated browser-based solution**, which uses Puppeteer and CAPTCHA solvers under the hood. 🔥
To circumvent these protections, we've added a **fully automated browser-based solution**, which uses Puppeteer and CAPTCHA solvers under the hood. 🔥
```ts
```ts
import{ChatGPTAPIBrowser}from'chatgpt'
import{ChatGPTAPIBrowser}from'chatgpt'
...
@@ -19,12 +17,18 @@ const result = await api.sendMessage('Hello World!')
...
@@ -19,12 +17,18 @@ const result = await api.sendMessage('Hello World!')
console.log(result.response)
console.log(result.response)
```
```
This solution is not lightweight, but it does work a lot more consistently than the previous REST API-based approach. For example, I'm currently using this approach to automate 10 concurrent OpenAI accounts for my [Twitter bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot). 😂
This solution is not lightweight, but it does work a lot more consistently than the previous REST API-based approach. For example, I'm currently using this approach to automate N concurrent OpenAI accounts for my [Twitter bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot). 😂
To use the updated version, **make sure you're using the latest version of this package and Node.js >= 18**. Then update your code following the examples below, paying special attention to the sections on [Authentication](#authentication), [Restrictions](#restrictions), and [CAPTCHAs](#captchas).
We recently added support for CAPTCHA automation using either [nopecha](https://nopecha.com/) or [2captcha](https://2captcha.com). Keep in mind that this package will be updated to use the official API as soon as it's released, so things should get much easier over time. 💪
We recently added support for CAPTCHA automation using either [nopecha](https://nopecha.com/) or [2captcha](https://2captcha.com). Keep in mind that this package will be updated to use the official API as soon as it's released, so things should get much easier over time. 💪
There are some restrictions to be aware of, however:
- Cloudflare doesn't like requests coming from data center IPs, so you'll either have to run it locally or use a residential IP proxy.
- You should only have one `sendMessage` request at a time per browser instance and OpenAI account.
- It can be difficult to reliably process `sendMessage` requests after awhile. My best advice for handling this is to wrap your usage in some basic retry logic as well as a daemon which restarts your Node.js process every hour or so. This is unfortunately a byproduct of there not being an official API, so keep that in mind before using this in production.
If you run into any issues, we do have a pretty active [Discord](https://discord.gg/v9gERj825w) with a bunch of ChatGPT hackers from the Node.js & Python communities.
Lastly, please consider starring this repo and <ahref="https://twitter.com/transitive_bs">following me on twitter <imgsrc="https://storage.googleapis.com/saasify-assets/twitter-logo.svg"alt="twitter"height="24px"align="center"></a> to help support the project.
Lastly, please consider starring this repo and <ahref="https://twitter.com/transitive_bs">following me on twitter <imgsrc="https://storage.googleapis.com/saasify-assets/twitter-logo.svg"alt="twitter"height="24px"align="center"></a> to help support the project.
Thanks && cheers,
Thanks && cheers,
...
@@ -90,7 +94,7 @@ async function example() {
...
@@ -90,7 +94,7 @@ async function example() {
```
```
<details>
<details>
<summary>Or, if you want to use the REST-based version:</summary>
<summary>Or, if you want to use the REST-based version: (not advised at this time)</summary>
```ts
```ts
import{ChatGPTAPI,getOpenAIAuth}from'chatgpt'
import{ChatGPTAPI,getOpenAIAuth}from'chatgpt'
...
@@ -199,7 +203,21 @@ A [basic demo](./demos/demo.ts) is included for testing purposes:
...
@@ -199,7 +203,21 @@ A [basic demo](./demos/demo.ts) is included for testing purposes:
npx tsx demos/demo.ts
npx tsx demos/demo.ts
```
```
A [conversation demo](./demos/demo-conversation.ts) is also included:
A [google auth demo](./demos/demo-google-auth.ts):
```bash
npx tsx demos/demo-google-auth.ts
```
A [demo showing on progress handler](./demos/demo-on-progress.ts):
```bash
npx tsx demos/demo-on-progress.ts
```
The on progress demo uses the optional `onProgress` parameter to `sendMessage` to receive intermediary results as ChatGPT is "typing".
A [conversation demo](./demos/demo-conversation.ts):
```bash
```bash
npx tsx demos/demo-conversation.ts
npx tsx demos/demo-conversation.ts
...
@@ -299,6 +317,7 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
...
@@ -299,6 +317,7 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
-[Twitter Bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot) powered by ChatGPT ✨
-[Twitter Bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot) powered by ChatGPT ✨
- Mention [@ChatGPTBot](https://twitter.com/ChatGPTBot) on Twitter with your prompt to try it out
- Mention [@ChatGPTBot](https://twitter.com/ChatGPTBot) on Twitter with your prompt to try it out
-[ChatGPT API Server](https://github.com/waylaidwanderer/node-chatgpt-api) - API server for this package with support for multiple OpenAI accounts, proxies, and load-balancing requests between accounts.