Network connectivity problems can prevent successful API requests.

Symptoms

  • Error messages like “connection timeout,” “failed to connect,” or “network error”
  • Long delays before errors appear

Solutions

  1. Check Internet Connection: Ensure your server has a stable internet connection

  2. Verify API Endpoint: Make sure the API endpoint URL is correct

// In your configuration file (config/llm.php)
'apiUrl' => 'https://api.openai.com/v1', // Correct URL
  1. Proxy Settings: If you’re behind a proxy, configure it properly
// Using custom HTTP client with proxy settings
use Cognesy\Http\HttpClient;
use Cognesy\Http\Data\HttpClientConfig;

$config = new HttpClientConfig(
    requestTimeout: 30,
    connectTimeout: 10,
    additionalOptions: ['proxy' => 'http://proxy.example.com:8080']
);

$httpClient = new HttpClient('guzzle', $config);
$inference = new Inference();
$inference->withHttpClient($httpClient);
  1. Firewall Rules: Check if your firewall is blocking outgoing connections to API endpoints

  2. DNS Resolution: Ensure your DNS is resolving the API domains correctly