Skip to main content

An unofficial Python wrapper for OpenAI's ChatGPT API

Project description


PyPi License PyPi

An unofficial Python wrapper for OpenAI's ChatGPT API


  • Cloudflare's anti-bot protection bypass using undetected_chromedriver
  • OpenAI / Google / Microsoft login support (experimental)
  • Captcha solvers support (2Captcha, PyPasser)
  • Headless machines support
  • Proxy support (only without basic auth)

Getting Started

Since version 0.3.0, this library is using only the undetected_chromedriver to bypass Cloudflare's anti-bot protection. requests module is no longer used due to the complexity of the protection. Please make sure you have Google Chrome / Chromium before using this wrapper.


pip install -U pyChatGPT


Obtaining session_token

  1. Go to and open the developer tools by F12.
  2. Find the __Secure-next-auth.session-token cookie in Application > Storage > Cookies >
  3. Copy the value in the Cookie Value field.


Interactive mode

python3 -m pyChatGPT

Import as a module

from pyChatGPT import ChatGPT

session_token = 'abc123'  # `__Secure-next-auth.session-token` cookie from
api = ChatGPT(session_token)  # auth with session token
api = ChatGPT(session_token, conversation_id='some-random-uuid')  # specify conversation id
api = ChatGPT(session_token, proxy='')  # specify proxy
api = ChatGPT(session_token, chrome_args=['--window-size=1920,768'])  # specify chrome args
api = ChatGPT(session_token, moderation=False)  # disable moderation
api = ChatGPT(session_token, verbose=True)  # verbose mode (print debug messages)

# auth with google login
api = ChatGPT(auth_type='google', email='', password='password')
# auth with microsoft login
api = ChatGPT(auth_type='microsoft', email='', password='password')
# auth with openai login (captcha solving using speech-to-text engine)
api = ChatGPT(auth_type='openai', email='', password='password')
# auth with openai login (manual captcha solving)
api = ChatGPT(
    auth_type='openai', captcha_solver=None,
    email='', password='password'
# auth with openai login (2captcha for captcha solving)
api = ChatGPT(
    auth_type='openai', captcha_solver='2captcha', solver_apikey='abc',
    email='', password='password'
# reuse cookies generated by successful login before login,
# if `login_cookies_path` does not exist, it will process logining  with `auth_type`, and save cookies to `login_cookies_path`
# only works when `auth_type` is `openai` or `google`
api = ChatGPT(auth_type='openai', email='', password='password',

resp = api.send_message('Hello, world!')

api.reset_conversation()  # reset the conversation
api.clear_conversations()  # clear all conversations
api.refresh_chat_page()  # refresh the chat page

Frequently Asked Questions

How do I get it to work on headless linux server?

# install chromium & X virtual framebuffer
sudo apt install chromium-browser xvfb

# start your script

How do I get it to work on Google Colab?

It is normal for the seession to be crashed when installing dependencies. Just ignore the error and run your script.

# install dependencies
!apt install chromium-browser xvfb
!pip install -U selenium_profiles pyChatGPT

# install chromedriver
from selenium_profiles.utils.installer import install_chromedriver
# start your script as normal
!python3 -m pyChatGPT


This project is inspired by


This project is not affiliated with OpenAI in any way. Use at your own risk. I am not responsible for any damage caused by this project. Please read the OpenAI Terms of Service before using this project.


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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyChatGPT- (24.0 kB view hashes)

Uploaded Source

Built Distribution

pyChatGPT- (23.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page