How to Configure Proxy Settings in GPT Academic: A Complete Guide
Set USE_PROXY = True in config.py and define your proxy URLs in the proxies dictionary, or override via environment variables HTTP_PROXY and HTTPS_PROXY before launching the application.
GPT Academic (binary-husky/gpt_academic) routes all LLM API traffic through configurable proxy servers to ensure connectivity behind corporate firewalls or in restricted networks. This guide explains how to configure proxy settings in GPT Academic using the configuration file, environment variables, and runtime overrides while referencing the actual source implementation.
Understanding Proxy Configuration Priority
GPT Academic reads proxy settings through three mechanisms in order of priority:
- Environment variables (
HTTP_PROXY,HTTPS_PROXY,ALL_PROXY,no_proxy) — highest priority config_private.py— overrides defaults if present- Static values in
config.py— default configuration location
The toolbox.ProxyManager class (lines 842-865 in toolbox.py) manages these settings at runtime, cleaning up stray environment variables to prevent proxy leakage to subprocesses.
Step-by-Step: Configure Proxy in config.py
Enable Proxy Usage
Locate config.py in the repository root and set the enable flag:
# config.py lines 20-22
USE_PROXY = True
If USE_PROXY remains False, the application ignores any proxy definitions and issues a warning during startup, as handled by shared_utils/config_loader.py (lines 93-97).
Define Proxy URLs
Configure the proxies dictionary with your specific proxy protocol and address:
# config.py lines 30-34
proxies = {
"http": "socks5h://127.0.0.1:1080",
"https": "socks5h://127.0.0.1:1080",
}
Supported protocols include http, https, and socks5h. The socks5h variant ensures DNS resolution occurs through the proxy rather than locally.
Override Proxy Settings via Environment Variables
For temporary configurations or containerized deployments, set environment variables before launching GPT Academic:
export HTTP_PROXY="http://127.0.0.1:7890"
export HTTPS_PROXY="http://127.0.0.1:7890"
export no_proxy="*"
python main.py
The no_proxy="*" setting prevents local addresses from routing through the proxy, protecting internal API calls. Note that main.py explicitly sets no_proxy='*' early in execution to safeguard internal communications.
Verifying Your Proxy Configuration
Using the Built-in Checker
GPT Academic includes check_proxy.py to validate connectivity:
from check_proxy import check_proxy
proxies = {"http": "socks5h://localhost:11284", "https": "socks5h://localhost:11284"}
ip = check_proxy(proxies, return_ip=True)
print(f"Proxy active. External IP: {ip}")
This function (lines 3-9 and 296-299 in check_proxy.py) returns the public IP address as seen by the proxy server, confirming successful routing.
Runtime Verification
Upon startup, GPT Academic logs the effective proxy configuration with the tag [PROXY]. Check the console output or logs to confirm the system recognizes your settings.
How Proxy Settings Are Applied in the Source Code
Understanding the internal flow helps troubleshoot configuration issues:
-
Configuration Loading:
shared_utils/config_loader.pycaches theUSE_PROXYflag andproxiesdictionary (lines 93-97). If disabled, it logs a warning and ignores proxy definitions. -
Request Routing: LLM bridge modules like
request_llms/bridge_chatgpt.py(lines 26-31) consume theproxiesdict when initializing HTTP clients, unlessdisable_proxy=Trueis passed. -
Environment Management:
toolbox.ProxyManager(lines 842-865 intoolbox.py) sets and removesHTTP_PROXY/HTTPS_PROXYenvironment variables around each request to prevent subprocess pollution. -
Special Adapters: Some modules like
edge_gpt_free.py(lines 313-321) check additional variables includingALL_PROXYandBING_PROXY_URLfor specific service requirements.
Summary
- Enable proxies by setting
USE_PROXY = Trueinconfig.py(lines 20-22). - Define endpoints in the
proxiesdictionary with protocol-specific URLs (lines 30-34). - Override temporarily using
HTTP_PROXYandHTTPS_PROXYenvironment variables. - Verify functionality with
check_proxy.pyor by checking startup logs for[PROXY]entries. - Understand internals:
config_loader.pyhandles caching,toolbox.ProxyManagermanages environment variables, and bridge modules apply settings per-request.
Frequently Asked Questions
How do I disable the proxy after enabling it?
Set USE_PROXY = False in config.py and restart the application. Alternatively, set the environment variable no_proxy="*" before launching to disable proxy routing for that session without modifying configuration files.
Why is GPT Academic ignoring my proxy settings?
Check that USE_PROXY is set to True in config.py (not config_private.py unless you intend to override). Also verify that environment variables like HTTP_PROXY aren't set to conflicting values, as these take precedence over file-based configuration according to the priority rules in toolbox.py.
Can I use different proxies for HTTP and HTTPS traffic?
Yes. The proxies dictionary in config.py supports separate entries for "http" and "https" keys. You can route HTTP requests through one proxy and HTTPS requests through another by specifying different URLs for each key.
What proxy protocols are supported?
GPT Academic supports standard http and https proxies, as well as socks5 and socks5h (the latter routes DNS queries through the proxy). Some specialized modules like edge_gpt_free.py also respect ALL_PROXY and BING_PROXY_URL environment variables for specific service integrations.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →