openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.6k stars 468 forks source link

Add proxy support #263

Open ovchinnikovndre1 opened 8 months ago

ovchinnikovndre1 commented 8 months ago

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

gehrisandro commented 8 months ago

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

fishfree commented 7 months ago

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

ebudmada commented 7 months ago

yes this feature would be useful

yarooze commented 6 months ago

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();
iPabro commented 3 months ago

For socks5 working like this

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