Reverse proxy for OpenAI chatgpt website API
Project description
ChatGPT-Proxy
Python version of OpenAI's ChatGPT web API proxy
Python alternative of ChatGPT-Proxy-V4
Use cookie cf_clearance
to pass Cloudflare browser check
_puid
no longer works
Requirements
- Access to chat.openai.com
Install
pip install chatgpt-proxy
Usage
Run as a service
Set these environment variables:
CF_CLEARANCE
: Cookiecf_clearance
USER_AGENT
: User-agent of your browser when you get the cookiecf_clearance
ACCESS_TOKEN
: (Optional) Obtains from herePROXY_TRUST_CLIENT
: (Optional) Trust requests from any client.
When set toTrue
, any requests without an access_token will be given the above access_token.
Default toFalse
, which will only use for refresh puid.HOST
: (Optional) Listen on host, default to127.0.0.1
PORT
: (Optional) Listen on port, default to7800
Or create a .env
file with your environment variables at where you want to run the proxy:
cf_clearance=YOUR_CF_CLEARANCE
user_agent=YOUR_USER_AGENT
access_token=YOUR_ACCESS_TOKEN
proxy_trust_client=False
host=127.0.0.1
port=7800
Note that environment variables will override the values in .env
file.
Then run: python -m chatgpt_proxy
Success
If you see this in console:
2023-01-01 00:00:00,000 - chatgpt_proxy.proxy - INFO - puid: user-xxxxxx
You are ready to go
The proxy is avaliable at http://host:port/backend-api/
Integrate into your FastAPI app
Check out __main__.py
from chatgpt_proxy import WebChatGPTProxy
proxy = WebChatGPTProxy(cf_clearance=CF_CLEARANCE, user_agent=USER_AGENT, access_token=ACCESS_TOKEN, trust=False)
app = FastAPI()
proxy.attach(app, path="/backend-api")
class WebChatGPTProxy
:
cf_clearance
: Cookiecf_clearance
user_agent
: User-agent of your browser when you get the cookiecf_clearance
access_token
: (Optional)trust
: (Optional) Trust requests from any client. When set to True, any requests without an access_token will be given the above access_token. Default to False, which will only use for refresh puid.
Behind a http proxy
You need to use the same ip address you used to get the cookie cf_clearance
Set HTTP_PROXY
and HTTPS_PROXY
or ALL_PROXY
environment variables.
This cannot be set in .env
file becauce httpx
(the package we used to send request) reads from environment variables only. See also httpx#Proxies.
Credits
- ChatGPT-Proxy-V4 https://github.com/acheong08/ChatGPT-Proxy-V4
- Implement reverse proxy in FastAPI https://github.com/tiangolo/fastapi/discussions/7382#discussioncomment-5136454
License
This work is licensed under the GNU Affero General Public License v3.0 or later, with the "CHATGPT-PROXY" exception.
"CHATGPT-PROXY" EXCEPTION TO THE AGPL
As a special exception, using this work in the following ways does not cause your program to be covered by the AGPL:
- Bundling the unaltered code or binary of this work in your program; or
- Interacting with this work through the provided inter-process communication interface, such as the HTTP API.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for chatgpt_proxy-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3dd74945ef041fc1d1df8b2b065ff1ece83a22fdeda8c5ff535116808418da9 |
|
MD5 | 563c5e5c910102d97c14e1da948243a7 |
|
BLAKE2b-256 | f22b477d4135ea2b8118ffaff1020fdf49e7f9febe4edf161e9f5dae9eb4aba6 |