PHPackages                             wordpress/php-ai-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. wordpress/php-ai-client

ActiveLibrary[API Development](/categories/api)

wordpress/php-ai-client
=======================

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

1.3.1(2mo ago)26236.6k↓25.2%57[20 issues](https://github.com/WordPress/php-ai-client/issues)[8 PRs](https://github.com/WordPress/php-ai-client/pulls)9GPL-2.0-or-laterPHPPHP &gt;=7.4

Since Jul 21Pushed 2mo ago13 watchersCompare

[ Source](https://github.com/WordPress/php-ai-client)[ Packagist](https://packagist.org/packages/wordpress/php-ai-client)[ Docs](https://github.com/WordPress/php-ai-client)[ RSS](/packages/wordpress-php-ai-client/feed)WikiDiscussions trunk Synced 1mo ago

READMEChangelog (10)Dependencies (42)Versions (28)Used By (9)

PHP AI Client
=============

[](#php-ai-client)

[*Part of the **AI Building Blocks for WordPress** initiative*](https://make.wordpress.org/ai/2025/07/17/ai-building-blocks)

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

General information
-------------------

[](#general-information)

This project is a PHP SDK, which can be installed as a Composer package. In WordPress, it could be bundled in plugins. It is however not a plugin itself.

While this project is stewarded by [WordPress AI Team](https://make.wordpress.org/ai/) members and contributors, it is technically WordPress agnostic. The gap the project addresses is relevant for not only the WordPress ecosystem, but the overall PHP ecosystem, so any PHP project could benefit from it. There is also no technical reason to scope it to WordPress, as communicating with AI models and their providers is independent of WordPress's built-in APIs and paradigms.

Installation
------------

[](#installation)

```
composer require wordpress/php-ai-client

```

Code examples
-------------

[](#code-examples)

### Text generation using a specific model

[](#text-generation-using-a-specific-model)

```
use WordPress\AiClient\AiClient;

$text = AiClient::prompt('Write a 2-verse poem about PHP.')
    ->usingModel(Google::model('gemini-2.5-flash'))
    ->generateText();
```

### Text generation using any compatible model from a specific provider

[](#text-generation-using-any-compatible-model-from-a-specific-provider)

```
use WordPress\AiClient\AiClient;

$text = AiClient::prompt('Write a 2-verse poem about PHP.')
    ->usingProvider('openai')
    ->generateText();
```

### Text generation using any compatible model

[](#text-generation-using-any-compatible-model)

```
use WordPress\AiClient\AiClient;

$text = AiClient::prompt('Write a 2-verse poem about PHP.')
    ->generateText();
```

### Text generation with additional parameters

[](#text-generation-with-additional-parameters)

```
use WordPress\AiClient\AiClient;

$text = AiClient::prompt('Write a 2-verse poem about PHP.')
    ->usingSystemInstruction('You are a famous poet from the 17th century.')
    ->usingTemperature(0.8)
    ->generateText();
```

### Text generation with multiple candidates using any compatible model

[](#text-generation-with-multiple-candidates-using-any-compatible-model)

```
use WordPress\AiClient\AiClient;

$texts = AiClient::prompt('Write a 2-verse poem about PHP.')
    ->generateTexts(4);
```

### Text generation using max tokens

[](#text-generation-using-max-tokens)

```
use WordPress\AiClient\AiClient;

$text = AiClient::prompt('Write a 80-verse poem with long stanzas about PHP.')
    ->usingSystemInstruction('You are a famous poet from the 17th century.')
    ->usingTemperature(0.8)
    ->usingMaxTokens(8000);
    ->generateText();
```

### Image generation using any compatible model

[](#image-generation-using-any-compatible-model)

```
use WordPress\AiClient\AiClient;

$imageFile = AiClient::prompt('Generate an illustration of the PHP elephant in the Caribbean sea.')
    ->generateImage();
```

See the [`PromptBuilder` class](https://github.com/WordPress/php-ai-client/blob/trunk/src/Builders/PromptBuilder.php) and its public methods for all the ways you can configure the prompt.

**More documentation is coming soon.**

Event Dispatching
-----------------

[](#event-dispatching)

The AI Client supports PSR-14 event dispatching for prompt lifecycle events. This allows you to hook into the generation process for logging, monitoring, or other integrations.

### Available Events

[](#available-events)

- `BeforeGenerateResultEvent` - Dispatched before a prompt is sent to the model
- `AfterGenerateResultEvent` - Dispatched after a result is received from the model

**Important:** Event listeners should not return a value, as they will be ignored. In order to modify data that is passed with the event object, you need to rely on setters on the event object. Any event data for which there are no setters on the event object is meant to be immutable or, in other words, read-only for the event listener.

### Connecting Your Event Dispatcher

[](#connecting-your-event-dispatcher)

To enable event dispatching, pass any PSR-14 compatible `EventDispatcherInterface` to the client:

```
use WordPress\AiClient\AiClient;

// Set your PSR-14 event dispatcher
AiClient::setEventDispatcher($yourEventDispatcher);

// Events will now be dispatched during generation
$text = AiClient::prompt('Hello, world!')
    ->generateText();
```

### Example: Logging Events

[](#example-logging-events)

```
use WordPress\AiClient\Events\BeforeGenerateResultEvent;
use WordPress\AiClient\Events\AfterGenerateResultEvent;

// In your event listener/subscriber
class AiEventListener
{
    public function onBeforeGenerate(BeforeGenerateResultEvent $event): void
    {
        $model = $event->getModel();
        $messages = $event->getMessages();
        $capability = $event->getCapability();

        // Log, monitor, or perform other actions
    }

    public function onAfterGenerate(AfterGenerateResultEvent $event): void
    {
        $result = $event->getResult();

        // Log the result, track usage, etc.
    }
}
```

Further reading
---------------

[](#further-reading)

For more information on the requirements and guiding principles, please review:

- [Glossary](./docs/GLOSSARY.md)
- [Requirements](./docs/REQUIREMENTS.md)
- [Architecture](./docs/ARCHITECTURE.md)
- [Prepublish Checklist](./docs/PREPUBLISH-CHECKLIST.md)

See the [contributing documentation](./CONTRIBUTING.md) for more information on how to get involved.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity51

Moderate usage in the ecosystem

Community39

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Recently: every ~6 days

Total

15

Last Release

61d ago

Major Versions

0.4.3 → 1.0.02026-02-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/a60abe9a2c42fe5cf2117b88aac2eab186f0ea3c969f1f4a29d4a09d831153b8?d=identicon)[felixarntz](/maintainers/felixarntz)

![](https://www.gravatar.com/avatar/d99a52e3a323417da88045cb7754e884899c54d42ab51287a2e8e4da51b8b1b0?d=identicon)[jeffpaul](/maintainers/jeffpaul)

---

Top Contributors

[![JasonTheAdams](https://avatars.githubusercontent.com/u/2024145?v=4)](https://github.com/JasonTheAdams "JasonTheAdams (468 commits)")[![felixarntz](https://avatars.githubusercontent.com/u/3531426?v=4)](https://github.com/felixarntz "felixarntz (341 commits)")[![borkweb](https://avatars.githubusercontent.com/u/430385?v=4)](https://github.com/borkweb "borkweb (43 commits)")[![saarnilauri](https://avatars.githubusercontent.com/u/36833033?v=4)](https://github.com/saarnilauri "saarnilauri (10 commits)")[![JosephGabito](https://avatars.githubusercontent.com/u/81974552?v=4)](https://github.com/JosephGabito "JosephGabito (8 commits)")[![dkotter](https://avatars.githubusercontent.com/u/916738?v=4)](https://github.com/dkotter "dkotter (6 commits)")[![aaronjorbin](https://avatars.githubusercontent.com/u/622599?v=4)](https://github.com/aaronjorbin "aaronjorbin (5 commits)")[![raftaar1191](https://avatars.githubusercontent.com/u/22215595?v=4)](https://github.com/raftaar1191 "raftaar1191 (3 commits)")[![desrosj](https://avatars.githubusercontent.com/u/359867?v=4)](https://github.com/desrosj "desrosj (2 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (2 commits)")[![Ref34t](https://avatars.githubusercontent.com/u/20759581?v=4)](https://github.com/Ref34t "Ref34t (2 commits)")[![mpeshev](https://avatars.githubusercontent.com/u/328189?v=4)](https://github.com/mpeshev "mpeshev (2 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![akkspros](https://avatars.githubusercontent.com/u/56331609?v=4)](https://github.com/akkspros "akkspros (1 commits)")[![chloe-pomegranate](https://avatars.githubusercontent.com/u/264397470?v=4)](https://github.com/chloe-pomegranate "chloe-pomegranate (1 commits)")[![huzaifaalmesbah](https://avatars.githubusercontent.com/u/63150399?v=4)](https://github.com/huzaifaalmesbah "huzaifaalmesbah (1 commits)")[![Jameswlepage](https://avatars.githubusercontent.com/u/36246732?v=4)](https://github.com/Jameswlepage "Jameswlepage (1 commits)")[![johnhooks](https://avatars.githubusercontent.com/u/20690965?v=4)](https://github.com/johnhooks "johnhooks (1 commits)")[![mujuonly](https://avatars.githubusercontent.com/u/459367?v=4)](https://github.com/mujuonly "mujuonly (1 commits)")[![nikunj8866](https://avatars.githubusercontent.com/u/24288574?v=4)](https://github.com/nikunj8866 "nikunj8866 (1 commits)")

---

Tags

apiaillm

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wordpress-php-ai-client/health.svg)

```
[![Health](https://phpackages.com/badges/wordpress-php-ai-client/health.svg)](https://phpackages.com/packages/wordpress-php-ai-client)
```

###  Alternatives

[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

963.1M35](/packages/getbrevo-brevo-php)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[php-tmdb/api

PHP wrapper for TMDB (TheMovieDatabase) API v3. Supports two types of approaches, one modelled with repositories, models and factories. And the other by simple array access to RAW data from The Movie Database.

424378.6k16](/packages/php-tmdb-api)[gemini-api-php/client

API client for Google's Gemini API

216221.4k5](/packages/gemini-api-php-client)[wordpress/wp-ai-client

An AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API.

11117.5k1](/packages/wordpress-wp-ai-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
