PHP AI Client

This is part of the AI Building Blocks for WordPress initiative. The main projects are PHP AI Client SDKPHP AI Client SDK A platform-agnostic library providing unified access to LLMs and embedding models from any major AI provider. Developed collaboratively with the PHP community. The WordPress AI Client SDK is the WordPress-specific package that adds REST API endpoints, API key management, and integrations through `AI_Client::prompt()`., Abilities APIAbilities API A core WordPress API (introduced in 6.9) that creates a central registry of capabilities, making WordPress functions discoverable and accessible to AI agents, automation tools, and developers. Transforms WordPress from isolated functions into a unified system., MCP AdapterMCP Adapter Translates WordPress abilities into Model Context Protocol format, allowing AI assistants like Claude and ChatGPT to discover and invoke WordPress capabilities as tools, resources, and prompts., and the AI Experiments PluginAI Experiments Plugin WordPress's AI laboratory bringing all building blocks together. Serves as both a user tool and developer reference implementation. First release (v0.1.0) includes Title Generation experiment..

Introduction

The PHP AI Client SDK (GitHub) provides shared infrastructure that lets WordPress plugins and other PHPPHP PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. https://www.php.net/manual/en/preface.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 providerProvider An AI service offering models for generation, embeddings, or other capabilities (e.g., Anthropic, Google, OpenAI). 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-agnosticProvider-Agnostic Software design that works with multiple service providers without being tied to one. Recommended for WordPress AI integrations. 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 APIAPI An API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. 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 pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party’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 APIREST API The REST API is an acronym for the RESTful Application Program Interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. It is how the front end of an application (think “phone app” or “website”) can communicate with the data store (think “database” or “file system”) https://developer.wordpress.org/rest-api/. endpoints to use AI capabilities in JavaScriptJavaScript JavaScript or JS is an object-oriented computer programming language commonly used to create interactive effects within web browsers. WordPress makes extensive use of JS for a better user experience. While PHP is executed on the server, JS executes within a user’s browser. https://www.javascript.com/. 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 UIUI UI is an acronym for User Interface - the layout of the page the user interacts with. Think ‘how are they doing that’ and less about what they are doing., or the underlying PHP package for lower-level projects such as a WP-CLIWP-CLI WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is http://wp-cli.org/ https://make.wordpress.org/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 CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress.. 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 SlackSlack Slack is a Collaborative Group Chat Platform https://slack.com/. The WordPress community has its own Slack Channel at https://make.wordpress.org/chat/. or explore the implementation.

#ai-building-blocks