{"id":15169619,"url":"https://github.com/softcreatr/php-perplexity-ai-sdk","last_synced_at":"2025-07-28T23:33:36.340Z","repository":{"id":201141437,"uuid":"707052291","full_name":"SoftCreatR/php-perplexity-ai-sdk","owner":"SoftCreatR","description":"A powerful and easy-to-use PHP SDK for the pplx API, allowing seamless integration of advanced AI-powered features into your PHP projects.","archived":false,"fork":false,"pushed_at":"2025-03-26T08:10:59.000Z","size":50,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-11T22:33:52.900Z","etag":null,"topics":["ai","api","api-client","api-wrapper","artificial-intelligence","gpt","gpt-3","gpt-4","hacktoberfest","llama","machine-learning","mistral","natural-language-processing","nlp","perplexity","php","pplx","replit","sdk"],"latest_commit_sha":null,"homepage":"https://docs.perplexity.ai","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoftCreatR.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"softcreatr","custom":["https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4"]}},"created_at":"2023-10-19T06:10:41.000Z","updated_at":"2025-07-07T18:32:23.000Z","dependencies_parsed_at":"2024-01-15T03:58:10.462Z","dependency_job_id":"60e5163b-dd12-4476-a643-02f52a63c1e1","html_url":"https://github.com/SoftCreatR/php-perplexity-ai-sdk","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"b90e5f49501e3cdd345d25e95a363e0ed579a1a9"},"previous_names":["softcreatr/php-perplexity-ai-sdk"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/SoftCreatR/php-perplexity-ai-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-perplexity-ai-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-perplexity-ai-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-perplexity-ai-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-perplexity-ai-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoftCreatR","download_url":"https://codeload.github.com/SoftCreatR/php-perplexity-ai-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-perplexity-ai-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264915878,"owners_count":23682945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","api-client","api-wrapper","artificial-intelligence","gpt","gpt-3","gpt-4","hacktoberfest","llama","machine-learning","mistral","natural-language-processing","nlp","perplexity","php","pplx","replit","sdk"],"created_at":"2024-09-27T07:04:08.049Z","updated_at":"2025-07-28T23:33:36.335Z","avatar_url":"https://github.com/SoftCreatR.png","language":"PHP","readme":"# PerplexityAI API Wrapper for PHP\n\n[![Build](https://img.shields.io/github/actions/workflow/status/SoftCreatR/php-perplexity-ai-sdk/.github/workflows/create-release.yml?branch=main)](https://github.com/SoftCreatR/php-perplexity-ai-sdk/actions/workflows/create-release.yml) [![Latest Release](https://img.shields.io/packagist/v/SoftCreatR/php-perplexity-ai-sdk?color=blue\u0026label=Latest%20Release)](https://packagist.org/packages/softcreatr/php-perplexity-ai-sdk) [![ISC licensed](https://img.shields.io/badge/license-ISC-blue.svg)](./LICENSE.md) [![Plant Tree](https://img.shields.io/badge/dynamic/json?color=brightgreen\u0026label=Plant%20Tree\u0026query=%24.total\u0026url=https%3A%2F%2Fpublic.ecologi.com%2Fusers%2Fsoftcreatr%2Ftrees)](https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4) [![Codecov branch](https://img.shields.io/codecov/c/github/SoftCreatR/php-perplexity-ai-sdk)](https://codecov.io/gh/SoftCreatR/php-perplexity-ai-sdk) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/SoftCreatR/php-perplexity-ai-sdk)](https://codeclimate.com/github/SoftCreatR/php-perplexity-ai-sdk)\n\nThis PHP library provides a simple wrapper for the PerplexityAI API, allowing you to easily integrate the PerplexityAI API into your PHP projects.\n\n## Features\n\n- Easy integration with PerplexityAI API\n- Supports all PerplexityAI API endpoints\n- Streaming support for real-time responses in chat completions\n- Utilizes PSR-17 and PSR-18 compliant HTTP clients and factories for making API requests\n\n## Requirements\n\n- PHP 8.1 or higher\n- A PSR-17 HTTP Factory implementation (e.g., [guzzle/psr7](https://github.com/guzzle/psr7) or [nyholm/psr7](https://github.com/Nyholm/psr7))\n- A PSR-18 HTTP Client implementation (e.g., [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) or [symfony/http-client](https://github.com/symfony/http-client))\n\n## Installation\n\nYou can install the library via [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require softcreatr/php-perplexity-ai-sdk\n```\n\n## Usage\n\nFirst, include the library in your project:\n\n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n```\n\nThen, create an instance of the `PerplexityAI` class with your API key, an HTTP client, an HTTP request factory, and an HTTP stream factory:\n\n```php\nuse SoftCreatR\\PerplexityAI\\PerplexityAI;\n\n$apiKey = 'your_api_key';\n\n// Replace these lines with your chosen PSR-17 and PSR-18 compatible HTTP client and factories\n$httpClient = new YourChosenHttpClient();\n$requestFactory = new YourChosenRequestFactory();\n$streamFactory = new YourChosenStreamFactory();\n$uriFactory = new YourChosenUriFactory();\n\n$pplx = new PerplexityAI($requestFactory, $streamFactory, $uriFactory, $httpClient, $apiKey);\n```\n\nNow you can call any supported PerplexityAI API endpoint using the magic method `__call`:\n\n```php\n$response = $pplx-\u003ecreateChatCompletion([], \n    [\n        'model' =\u003e 'sonar',\n        'messages' =\u003e [\n            [\n                'role' =\u003e 'system',\n                'content' =\u003e 'Be precise and concise.'\n            ],\n            [\n                'role' =\u003e 'user',\n            '   content' =\u003e 'How many stars are there in our galaxy?'\n        ]\n    ],\n]);\n\n// Process the API response\nif ($response-\u003egetStatusCode() === 200) {\n    $responseObj = json_decode($response-\u003egetBody()-\u003egetContents(), true);\n    \n    print_r($responseObj);\n} else {\n    echo \"Error: \" . $response-\u003egetStatusCode();\n}\n```\n\n### Streaming Example\n\nYou can enable real-time streaming for chat completions:\n\n```php\n$streamCallback = static function ($data) {\n    if (isset($data['choices'][0]['delta']['content'])) {\n        echo $data['choices'][0]['delta']['content'];\n    }\n};\n\n$pplx-\u003ecreateChatCompletion([],\n    [\n        'model' =\u003e 'sonar',\n        'messages' =\u003e [\n            [\n                'role' =\u003e 'user',\n                'content' =\u003e 'Tell me a story about a brave knight.',\n            ],\n        ],\n        'stream' =\u003e true,\n    ],\n    $streamCallback\n);\n```\n\nFor more details on how to use each endpoint, refer to the [PerplexityAI API documentation](https://docs.perplexity.ai/reference), and the [examples](https://github.com/SoftCreatR/php-perplexity-ai-sdk/tree/main/examples) provided in the repository.\n\n## Supported Methods\n\n### Chat Completions\n-   [Create Chat Completion](https://docs.perplexity.ai/api-reference/chat-completions) - [Example](https://github.com/SoftCreatR/php-perplexity-ai-sdk/blob/main/examples/chat/createChatCompletion.php)\n  -   `createChatCompletion(array $options = [])`\n\n## Changelog\n\nFor a detailed list of changes and updates, please refer to the [CHANGELOG.md](https://github.com/SoftCreatR/php-perplexity-ai-sdk/blob/main/CHANGELOG.md) file. We adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and document notable changes for each release.\n\n## Known Problems and limitations\n\n### Streaming Support\n\nStreaming is now supported for real-time token generation in chat completions. Please make sure you are handling streams correctly using a callback, as demonstrated in the examples.\n\n## License\n\nThis library is licensed under the ISC License. See the [LICENSE](https://github.com/SoftCreatR/php-perplexity-ai-sdk/blob/main/LICENSE.md) file for more information.\n\n## Maintainers 🛠️\n\n\u003ctable\u003e\n\u003ctr\u003e\n    \u003ctd style=\"text-align:center;word-wrap:break-word;width:150px;height: 150px\"\u003e\n        \u003ca href=https://github.com/SoftCreatR\u003e\n            \u003cimg src=https://avatars.githubusercontent.com/u/81188?v=4 width=\"100;\" alt=\"Sascha Greuel\"/\u003e\n            \u003cbr /\u003e\n            \u003csub style=\"font-size:14px\"\u003e\u003cb\u003eSascha Greuel\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Contributors ✨\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n","funding_links":["https://github.com/sponsors/softcreatr","https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftcreatr%2Fphp-perplexity-ai-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftcreatr%2Fphp-perplexity-ai-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftcreatr%2Fphp-perplexity-ai-sdk/lists"}