PHP code example of softcreatr / php-perplexity-ai-sdk
1. Go to this page and download the library: Download softcreatr/php-perplexity-ai-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/ */
softcreatr / php-perplexity-ai-sdk example snippets
declare(strict_types=1);
leHttp\Psr7\HttpFactory;
use SoftCreatR\PerplexityAI\PerplexityAI;
$factory = new HttpFactory();
$perplexity = new PerplexityAI(
requestFactory: $factory,
streamFactory: $factory,
uriFactory: $factory,
httpClient: new Client(['stream' => true]),
apiKey: (string) getenv('PERPLEXITY_API_KEY'),
);
use const JSON_THROW_ON_ERROR;
$response = $perplexity->createAgentResponse([
'model' => 'openai/gpt-5-mini',
'input' => 'Give me a one-sentence summary of PSR-18.',
]);
$result = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);