Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Timeout is too short
  • Loading branch information
kargnas committed Aug 24, 2025
commit 2c3a91692c420fdc92994a7e1009854725637fcf
9 changes: 7 additions & 2 deletions src/AI/Clients/AnthropicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public function messages()
*/
public function request(string $method, string $endpoint, array $data = []): array
{
$timeout = 1800; // 30 minutes

$response = Http::withHeaders([
'x-api-key' => $this->apiKey,
'anthropic-version' => $this->apiVersion,
'content-type' => 'application/json',
])->$method("{$this->baseUrl}/{$endpoint}", $data);
])->timeout($timeout)->$method("{$this->baseUrl}/{$endpoint}", $data);

if (! $response->successful()) {
$statusCode = $response->status();
Expand Down Expand Up @@ -283,6 +285,9 @@ public function requestStream(string $method, string $endpoint, array $data, cal
'accept: application/json',
];

// Set timeout to 30 minutes for streaming
$timeout = 1800; // 30 minutes

// Initialize cURL
$ch = curl_init();

Expand All @@ -291,7 +296,7 @@ public function requestStream(string $method, string $endpoint, array $data, cal
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_TIMEOUT, 3000);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

if (strtoupper($method) !== 'GET') {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
Expand Down
12 changes: 11 additions & 1 deletion src/AI/Clients/GeminiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ class GeminiClient
public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
$this->client = \Gemini::client($apiKey);

// Set timeout to 30 minutes
$timeout = 1800; // 30 minutes

// Create client with timeout configuration
$this->client = \Gemini::factory()
->withApiKey($apiKey)
->withHttpClient(new \GuzzleHttp\Client([
'timeout' => $timeout,
]))
->make();
}

public function request(string $model, array $contents): array
Expand Down
10 changes: 7 additions & 3 deletions src/AI/Clients/OpenAIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public function __construct(string $apiKey)
*/
public function request(string $method, string $endpoint, array $data = []): array
{
$timeout = 1800; // 30 minutes

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$this->apiKey,
'Content-Type' => 'application/json',
])->$method("{$this->baseUrl}/{$endpoint}", $data);
])->timeout($timeout)->$method("{$this->baseUrl}/{$endpoint}", $data);

if (! $response->successful()) {
throw new \Exception("OpenAI API error: {$response->body()}");
Expand Down Expand Up @@ -173,8 +175,10 @@ public function requestStream(string $method, string $endpoint, array $data, cal
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);

$timeout = 1800; // 30 minutes
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // Keep connection timeout at 30 seconds
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

if (strtoupper($method) !== 'GET') {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
Expand Down