1
Set the Proxy Environment Variable
You can set a global proxy for all providers in G4F by setting the Replace
G4F_PROXY
environment variable. This can be useful if you want to hide or change your IP address for the providers.To set the proxy environment variable, run the following command in your terminal:http://host:port
with the actual proxy URL and port you want to use.2
Configure Proxies in the Client
You can also configure proxies directly in the G4F client. When creating a new The
Client
instance, you can pass the proxies
parameter to specify the proxy settings.proxies
parameter accepts a dictionary with the following keys:"all"
: Specifies the proxy URL for all requests."https"
: Specifies the proxy URL for HTTPS requests only.
"all"
and "https"
are provided, the "https"
proxy will be used for HTTPS requests, and the "all"
proxy will be used for other requests.3
Retrieve the Configured Proxy
You can retrieve the currently configured proxy using the This will return the proxy URL if one is configured, either through the
get_proxy()
method of the Client
instance.proxies
parameter or the G4F_PROXY
environment variable. If no proxy is configured, it will return None
.4
Use the Configured Proxy
Once you have configured the proxy, it will be automatically used for all requests made through the G4F client. You can proceed with using the various methods provided by the client, such as The above code will send the request through the configured proxy, ensuring that your IP address is hidden or changed as per the proxy settings.
client.chat.completions.create()
, and the requests will be routed through the specified proxy.