<?php
use Cognesy\Http\Config\HttpClientConfig;use Cognesy\Http\HttpClient;
// Create a custom HTTP client with longer timeouts
$config = new HttpClientConfig(
requestTimeout: 180, // 3 minutes for the entire request
connectTimeout: 10, // 10 seconds to establish connection
idleTimeout: 60 // 60 seconds allowed between stream chunks
);
$httpClient = new HttpClient('guzzle', $config);
$inference = new Inference();
$inference->withHttpClient($httpClient);
// Use streaming with the custom client
$response = $inference->with(
messages: 'Write a long story about a space explorer.',
options: ['stream' => true]
);
$stream = $response->stream()->responses();
foreach ($stream as $partial) {
echo $partial->contentDelta;
flush();
}
// @doctest id="0ae0"