Skip to content

Commit 698b828

Browse files
committed
feat(http): add configurable HTTP handler with Guzzle HTTP client support
1 parent 6ee4db7 commit 698b828

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

config/openai.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,15 @@
4646
*/
4747

4848
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30),
49+
50+
/*
51+
|--------------------------------------------------------------------------
52+
| HTTP Handler
53+
|--------------------------------------------------------------------------
54+
|
55+
| Define a custom HTTP handler (class-string or callable) for OpenAI requests.
56+
| Useful for adding Laravel Http Events, logging, or retries via Guzzle HandlerStack.
57+
| Base Handler: OpenAI\Laravel\Http\Handler::class
58+
*/
59+
'http_handler' => env('OPENAI_HTTP_HANDLER', null),
4960
];

src/ServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OpenAI\Contracts\ClientContract;
1212
use OpenAI\Laravel\Commands\InstallCommand;
1313
use OpenAI\Laravel\Exceptions\ApiKeyIsMissing;
14+
use OpenAI\Laravel\Http\Handler;
1415

1516
/**
1617
* @internal
@@ -35,7 +36,10 @@ public function register(): void
3536
$client = OpenAI::factory()
3637
->withApiKey($apiKey)
3738
->withOrganization($organization)
38-
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)]));
39+
->withHttpClient(new \GuzzleHttp\Client([
40+
'timeout' => config('openai.request_timeout', 30),
41+
'handler' => Handler::resolve(config('openai.http_handler')),
42+
]));
3943

4044
if (is_string($project)) {
4145
$client->withProject($project);

0 commit comments

Comments
 (0)