Polyglot \ Advanced
Customizing HTTP Client
Polyglot \ Advanced
Customizing HTTP Client
Learn how to use custom HTTP clients in Polyglot.
Polyglot allows you to use custom HTTP clients for specific connection requirements:
<?php
use Cognesy\Polyglot\LLM\Inference;
use Cognesy\Http\HttpClient;
use Cognesy\Http\Data\HttpClientConfig;
// Create a custom HTTP client configuration
$httpConfig = new HttpClientConfig(
connectTimeout: 5, // 5 seconds connection timeout
requestTimeout: 60, // 60 seconds request timeout
idleTimeout: 120, // 120 seconds idle timeout for streaming
maxConcurrent: 10, // Maximum 10 concurrent requests
failOnError: true, // Throw exceptions on HTTP errors
);
// Create a custom HTTP client
$httpClient = new HttpClient('guzzle', $httpConfig);
// Use the custom HTTP client with Inference
$inference = new Inference();
$inference->withHttpClient($httpClient);
// Make a request with the custom HTTP client
$response = $inference->create(
messages: 'This request uses a custom HTTP client.'
)->toText();
echo $response;