client icon indicating copy to clipboard operation
client copied to clipboard

Add proxy support

Open ovchinnikovndre1 opened this issue 1 year ago • 5 comments

Hi. How do I add proxy support? I tried it like this : $proxies = [ 'http' => 'http://login:pass@ip:port', ];

    $client = new Client([
        RequestOptions::PROXY => $proxies,
        RequestOptions::VERIFY => false,
        RequestOptions::TIMEOUT => 30,
    ]);

    $this->client = OpenAI::factory()
                          ->withApiKey(config('openai.api_key'))
                          ->withHttpClient($client)
                          ->make();
                          
  

But I still get 500 error /var/www/vendor/openai-php/client/src/Resources/Chat.php ", line: 32

ovchinnikovndre1 avatar Nov 16 '23 16:11 ovchinnikovndre1

@ovchinnikovndre1 Please provide more information. At least the exception message and stack trace.

gehrisandro avatar Nov 16 '23 22:11 gehrisandro

+1 pls Sometimes we need set HTTP/SOCKS5 proxy to access api.openai.com

fishfree avatar Nov 23 '23 22:11 fishfree

yes this feature would be useful

ebudmada avatar Dec 01 '23 01:12 ebudmada

Hi. How do I add proxy support? I tried it like this : $proxies = [ 'http' => 'http://login:pass@ip:port', ];

This works for me:

    $client = \OpenAI::factory()
        ->withApiKey($apiKey)
        ->withHttpClient($client = new \GuzzleHttp\Client([
            'proxy' => 'http://my.proxy.url:80',
        ]))
        ->make();

yarooze avatar Dec 27 '23 11:12 yarooze

For socks5 working like this

$client = \OpenAI::factory()
        ->withApiKey($apiKey)
        ->withHttpClient($client = new \GuzzleHttp\Client([
            'proxy' => 'socks5://USER:PASSWORD@ip:port'
        ]))
        ->make();

iPabro avatar Apr 09 '24 00:04 iPabro