PHP code example of predictflow / sdk

1. Go to this page and download the library: Download predictflow/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

predictflow / sdk example snippets


new PredictFlow\Sdk\PredictFlow(
    apiKey: 'pk_live_...',
    httpClient: $yourPsr18Client,
    requestFactory: $yourPsr17Factory,
    streamFactory: $yourPsr17Factory,
);

use PredictFlow\Sdk\PredictFlow;

$client = new PredictFlow(apiKey: 'pk_live_...'); // or set PREDICTFLOW_API_KEY

$stores = $client->stores->list();
$forecast = $client->products->forecast(productId: 'prod_123', horizonDays: 30);
echo $forecast['forecast_data'];

use PredictFlow\Sdk\Exceptions\{
    AuthenticationException,
    NotFoundException,
    ValidationException,
    RateLimitException,
    PredictFlowException,
};

try {
    $forecast = $client->products->forecast('prod_missing');
} catch (AuthenticationException $e) {
    echo 'Check your API key';
} catch (NotFoundException $e) {
    echo 'Product not found';
} catch (RateLimitException $e) {
    echo "Rate limited, retry after {$e->retryAfterSeconds}s";
} catch (ValidationException $e) {
    echo "Invalid request: {$e->getMessage()}";
} catch (PredictFlowException $e) {
    echo "API error [{$e->status}]: {$e->getMessage()}";
}

$client = new PredictFlow(
    apiKey: 'pk_live_...',              // or PREDICTFLOW_API_KEY env var
    baseUrl: 'https://predictflow.co/api/v1', // default
    timeoutSeconds: 30.0,
    maxRetries: 2,                       // applies to GET/PUT/DELETE by default
    defaultHeaders: ['X-Custom-App' => 'my-integration/1.0'],
);