itzmekhokan / ai-provider-for-perplexity
AI Provider for Perplexity for the PHP AI Client SDK. Works as both a Composer package and WordPress plugin.
Package info
github.com/itzmekhokan/ai-provider-for-perplexity
pkg:composer/itzmekhokan/ai-provider-for-perplexity
Requires
- php: >=7.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/php-compatibility: dev-develop
- phpstan/phpstan: ~2.1
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.7 || ^4.0
- wordpress/php-ai-client: ^0.4 || dev-trunk
Suggests
- wordpress/php-ai-client: Required. The core PHP AI Client SDK that this provider extends.
This package is auto-updated.
Last update: 2026-07-05 11:46:37 UTC
README
AI Provider for Perplexity for the WordPress AI Client. Works as both a Composer package and a WordPress plugin.
This provider registers Perplexity with the AI Client, exposing Perplexity's Sonar models (Sonar, Sonar Pro, Sonar Reasoning, Sonar Reasoning Pro, and Sonar Deep Research) for web-grounded text generation through Perplexity's OpenAI-compatible Chat Completions API.
Requirements
- PHP 7.4+
- WordPress 6.9+ (when used as a plugin)
- The
wordpress/php-ai-clientSDK - A Perplexity API key from the Perplexity API settings
How it works
Perplexity exposes an OpenAI-compatible Chat Completions API, so this provider is intentionally thin:
| Class | Responsibility |
|---|---|
Provider\PerplexityProvider |
Registers the provider, base URL (https://api.perplexity.ai), API-key auth, and metadata. |
Metadata\PerplexityModelMetadataDirectory |
Defines the supported Sonar models and maps capabilities/options. |
Provider\PerplexityProviderAvailability |
Verifies the API key with a minimal text generation request. |
Models\PerplexityTextGenerationModel |
Sends POST /chat/completions via the shared OpenAI-compatible base class. |
Because Perplexity speaks the Chat Completions format, PerplexityTextGenerationModel extends
AbstractOpenAiCompatibleTextGenerationModel from the SDK and only overrides request construction.
Unlike most providers, Perplexity does not expose a model listing endpoint for its Sonar chat models, so the supported models are defined statically and availability is checked with a minimal text generation request rather than a list-models request.
Supported capabilities
- Web-grounded text generation (chat) with the Sonar model family
- Chat history / multi-turn conversations
- JSON / structured output
Installation
As a WordPress plugin
Copy this directory into wp-content/plugins/ and activate it alongside the WordPress AI Client.
As a Composer package
composer require itzmekhokan/ai-provider-for-perplexity
Author
License
GPL-2.0-or-later