Package: chatgpt-proxy
ChatGPT-ProxyPython version of OpenAI's ChatGPT web API proxyPython alternative ofChatGPT-Proxy-V4Use cookiecf_clearanceto pass Cloudflare browser check_puidno longer worksRequirementsAccess to chat.openai.comInstallpip install chatgpt-proxyUsageFor how to get a usablecf_clearancecookie, checkout issue#1(Chinese only sorry)Run as a serviceSet these environment variables:CF_CLEARANCE: (Optional) Cookiecf_clearanceUSER_AGENT: (Optional) User-agent of your browser when you get the cookiecf_clearanceACCESS_TOKEN: (Optional) Obtains fromherePUID: (Optional) Cookie_puid, still needed to start a conversation for plus account (?)
When set a plus account's access_token, this can be automatically refreshPROXY_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.1PORT: (Optional) Listen on port, default to7800MOD_ACCESS_TOKEN: (Optional) Update info like cf_clearance through http request
requires you set this access_token inAuthorizationHeaderOr create a.envfile with your environment variables at where you want to run the proxy:cf_clearance=YOUR_CF_CLEARANCEuser_agent=YOUR_USER_AGENTaccess_token=YOUR_ACCESS_TOKENpuid=ANY_VALID_PUIDproxy_trust_client=Falsehost=127.0.0.1port=7800mod_access_token=YOUR_MOD_ACCESS_TOKENNote that environment variables will override the values in.envfile.Then run:python -m chatgpt_proxySuccessIf you see this in console:2023-01-01 00:00:00,000 - chatgpt_proxy.proxy - INFO - puid: user-xxxxxxYou are ready to goThe proxy is avaliable athttp://host:port/backend-api/Integrate into your FastAPI appCheck out__main__.pyfromchatgpt_proxyimportWebChatGPTProxyproxy=WebChatGPTProxy(cf_clearance=CF_CLEARANCE,user_agent=USER_AGENT,access_token=ACCESS_TOKEN,trust=False)app=FastAPI()proxy.attach(app,path="/backend-api")classWebChatGPTProxy:cf_clearance: Cookiecf_clearanceuser_agent: User-agent of your browser when you get the cookiecf_clearanceaccess_token: (Optional)puid: (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 proxyYou need to use the same ip address you used to get the cookiecf_clearanceSetHTTP_PROXYandHTTPS_PROXYorALL_PROXYenvironment variables.Thiscannot be setin.envfile becaucehttpx(the package we used to send request) reads from environment variables only. See alsohttpx#Proxies.CreditsChatGPT-Proxy-V4https://github.com/acheong08/ChatGPT-Proxy-V4Implement reverse proxy in FastAPIhttps://github.com/tiangolo/fastapi/discussions/7382#discussioncomment-5136454LicenseThis work is licensed under theGNU Affero General Public License v3.0or later, with the "CHATGPT-PROXY" exception."CHATGPT-PROXY" EXCEPTION TO THE AGPLAs 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; orInteracting with this work through the provided inter-process communication interface, such as the HTTP API.