PHP AI Client


This is part of the AI Building Blocks for WordPress initiative. The main projects are PHP AI Client SDK, Abilities API, MCP Adapter, and the AI Experiments Plugin.

Introduction

The PHP AI Client SDK (GitHub) provides shared infrastructure that lets WordPress plugins and other PHP projects integrate AI capabilities rapidly and flexibly. Similar to projects like the Vercel AI SDK, it offers a unified interface that works across all AI providers – from simple text generation to complex multimodal operations, streaming responses, and long-running tasks.

Developers specify what AI capabilities they need, and users manage their provider credentials in one place. Those credentials then work automatically across all compatible plugins on their site.

The SDK addresses both user needs and developer needs:

  • A provider-agnostic approach puts the user first. The WordPress site administrator(s) choose which provider and/or model they want to configure and use, and they can provide API credentials in a single place. Any plugins with AI features just work. No more vendor lock-in.
  • Developers can focus on building AI features, not AI infrastructure. Instead of trying to find an unofficial SDK for a single provider or having to even build it yourself, the SDK gives developers the central infrastructure to get started quickly and focus on the user benefits rather than their own plugin’s technical plumbing. No more reinventing the wheel.

How It Works

The API adapts to different developer needs. Some plugin solutions may require specific models, while others just need any text completion capability. The PHP AI Client SDK handles all the complexity behind the scenes. Different authentication methods, API formats, streaming protocols, and provider quirks all work through the same clean interface.

Here is a simple tentative code example for generating text using a specific model:

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

And the same example, but written in a model and provider agnostic way:

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

The Problem It Solves

Today, every WordPress plugin with AI features rebuilds the same infrastructure: provider integrations, API key management, response normalization, error handling. Users enter the same credentials multiple times and deal with inconsistent experiences. When providers change their APIs, every plugin breaks separately.

It is worth highlighting that these problems not only exist in WordPress, but in more or less every PHP project that aims to use AI in a provider agnostic way. The only truly provider agnostic SDKs that exist to date are for other tech stacks that are not interoperable with general PHP projects – either different server-side languages (e.g. the Vercel AI SDK for NodeJS) or specific platforms (Drupal’s AI module).

The PHP AI Client SDK centralizes this complexity for the PHP ecosystem, and in WordPress specifically. One integration point handles all providers. One credential system serves all plugins. When providers update or new ones emerge, the changes happen once and benefit everyone. The architecture is designed with latest trends like multimodal-first in mind and even anticipates future shifts like client-side or browser-based AI.

Built Together

The PHP AI Client SDK technically consists of two Composer packages:

  • The underlying PHP package provides the unified AI interface, and it is WordPress agnostic. It is a collaborative effort with the wider PHP community.
  • This is complemented by another WordPress specific package that adds features technically tied to WordPress, such as the shared settings page for AI API credentials, connection to the Abilities API, and the REST API endpoints to use AI capabilities in JavaScript as well.

This modular approach means when any community adds a provider or improves performance, everyone benefits while each platform maintains its unique experience.

For WordPress developers, this architecture offers flexibility. Use the WordPress package for the full experience with admin UI, or the underlying PHP package for lower-level projects such as a WP-CLI integration. While also available as a plugin for testing, these Composer packages are the official adoption path – require them today, ship plugins with AI capabilities, and seamlessly transition if these become part of WordPress Core. Multiple plugins can use the same packages without conflicts, with Composer handling dependencies.

Moving Forward

As AI becomes essential to WordPress, this SDK provides the sustainable foundation. It’s designed to grow with emerging capabilities – new modalities, advanced features, novel deployment models. The focus now is expanding provider support and refining the developer experience based on real-world usage.

Please join the discussion in #core-ai on Slack or explore the implementation.

#ai-building-blocks