Download the PHP package softcreatr/php-perplexity-ai-sdk without Composer

On this page you can find all versions of the php package softcreatr/php-perplexity-ai-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-perplexity-ai-sdk

Perplexity API SDK for PHP

Tests Latest Release

A lightweight PSR-17/PSR-18 client for the current Perplexity API, with examples for every exposed SDK method, SSE streaming, structured errors, compatible endpoint overrides, and separate organization analytics authentication.

Requirements

Guzzle is used below because it provides both the PSR-17 factories and PSR-18 client implementation. The SDK itself depends only on the PSR interfaces, so other compliant implementations remain supported.

Installation

Client Setup

Keep API keys on the server and out of source control.

Agent API

The Agent API provides model and tool orchestration through a unified response interface.

Endpoint methods return a PSR-7 ResponseInterface, including calls that deliver SSE events to a callback.

Sonar API

Sonar provides Perplexity's search-grounded chat completions.

Arguments

Body-only endpoints use a single body array:

For endpoints with path parameters, a single combined array is the preferred v3 form. Path fields are separated from query or body fields using the endpoint template:

The v2 two-array form remains supported for existing integrations:

For GET and DELETE methods, non-path values become RFC 3986 query parameters. Path parameter values are URL encoded. The explicit form is available when method names are determined at runtime:

Streaming

Set stream to true and pass a callback. The decoder supports arbitrarily split chunks, CRLF and LF delimiters, comments, multiline data fields, final unterminated frames, and [DONE].

An ordinary JSON response is still returned when a callback is supplied without requesting an SSE stream. For a transport that exposes a response before buffering its complete body, implement StreamingClientInterface. Other PSR-18 clients remain supported and use their normal sendRequest() behavior.

Errors

4xx and 5xx responses throw PerplexityAIException. The exception keeps the parsed API error, raw response body, response headers, status code, and x-request-id for diagnostics.

PSR-18 transport failures are wrapped in PerplexityAIException and retain the original exception as getPrevious().

Examples

Examples load the ignored project-level .env through examples/PerplexityAIFactory.php:

Set PERPLEXITY_ANALYTICS_API_KEY only when running examples under examples/analytics.

Supported Methods

The catalog follows the current Perplexity API reference.

Agent

SDK method HTTP route Request body Example
createAgentResponse POST /v1/agent json PHP
retrieveAgentResponse GET /v1/agent/{id} none PHP
listAgentResponseFiles GET /v1/agent/{id}/files none PHP
downloadAgentResponseFile GET /v1/agent/{id}/files/{file_id}/content none PHP
cancelAgentResponse POST /v1/agent/{id}/cancel none PHP

Sonar

SDK method HTTP route Request body Example
createChatCompletion POST /v1/sonar json PHP
createAsyncChatCompletion POST /v1/async/sonar json PHP
listAsyncChatCompletions GET /v1/async/sonar none PHP
retrieveAsyncChatCompletion GET /v1/async/sonar/{api_request} none PHP

Search

SDK method HTTP route Request body Example
search POST /search json PHP

Embeddings

SDK method HTTP route Request body Example
createEmbedding POST /v1/embeddings json PHP
createContextualizedEmbedding POST /v1/contextualizedembeddings json PHP

Models

SDK method HTTP route Request body Example
listModels GET /v1/models none PHP

Router

SDK method HTTP route Request body Example
createRouterChatCompletion POST /router/v1/chat/completions json PHP
createRouterMessage POST /router/v1/messages json PHP
createRouterResponse POST /router/v1/responses json PHP
listRouterModels GET /router/v1/models none PHP
retrieveRouterModel GET /router/v1/models/{model} none PHP

Authentication

SDK method HTTP route Request body Example
generateAuthToken POST /generate_auth_token json PHP
revokeAuthToken POST /revoke_auth_token json PHP

These operations manage live credentials. Review the examples before running them.

Analytics

SDK method HTTP route Request body Example
getComputerUsageAnalytics GET /v1/analytics/computer/usage none PHP
getComputerUsageAnalyticsV2 GET /v2/analytics/computer/usage none PHP

Analytics endpoints require a separate organization analytics API key. The example factory reads it from PERPLEXITY_ANALYTICS_API_KEY.

Custom API Origin

Pass a hostname or absolute base URL through the constructor's origin argument. basePath overrides any path already present in an absolute origin. The examples read PERPLEXITY_API_ORIGIN and PERPLEXITY_API_BASE_PATH from .env.

Development

License

Licensed under the ISC License.


All versions of php-perplexity-ai-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ~8.2.35 || ~8.3.36 || ~8.4.27 || ~8.5.12 || ~8.6.0
ext-json Version *
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package softcreatr/php-perplexity-ai-sdk contains the following files

Loading the files please wait ...