Proxy exclusion for API, NO_PROXY=api.openai.com?

Hi, I’m currently trying to exclude the calls I make to the api from running through my proxy because it seems to have been blocked for some reason (it’s located in the US).
Anyway, I would like to do something like :
NO_PROXY=http://openai.com
and the request would be runned on my IP not through the proxy, the issue is, it doesn’t seem to work. I can run my python script properlly when I use my IP so it is not an implementation issue.

I couldn’t get things like :

_http_client = _httpx.Client(proxies=proxies)
chatgpt_client = OpenAI(api_key=api_key,
http_client=_http_client # Configure a custom httpx client)

to work either, it said :

Request URL is missing an ‘http://’ or ‘https://’ protocol.

to the best of my knowledge this would be a httpx error but I couldn’t solve it.

I also tried setting some ENV variable like OPENAI_PROXY but same thing, doesn’t seem to work.

If anyone has idea I would gladly take them !
Thanks.

I put a forward proxy on my firewall with a bad cert SSL catcher, and configured the OS to use it. It broke my Python chatbot.

Then added this to make it work again:

import os
from openai import OpenAI
try:
    os.environ['NO_PROXY'] = os.environ['NO_PROXY'] + ',' + 'api.openai.com'
except:
    os.environ['NO_PROXY'] = 'api.openai.com'
    
client = OpenAI()

The httpx library that the openai python SDK module uses respects this no_proxy environment variable.

2 Likes

I tried, it didn’t seem to help but I managed to fix my issue.
It actually had nothing to do with the proxy being banned at least I don’t think so, but it had to do with the character Pi going through the proxy with the request and somehow bugged everything.

It was a nightmare to debug but thanks anyway for your idea.

1 Like