PHP AI Client SDK ![rw-book-cover](https://img.youtube.com/vi/lNAh5B0xh6I/maxresdefault.jpg) Okay. Hello. Hi. We're live and we are going to to explore a little bit this project called PHP AI client SDK which basically allows any WordPress project to to connect to external models. So yeah, let's talk a little bit about that and how it connects with all the AI related projects in WordPress such as uh the abilities API, the MCP adapter, and the AI experiments plug-in. So I'm going to share this link here. Um so yeah let's start let's start from a diagram that I have uh somewhere. So let me let me find it. Where do I have it? See if I can find it in my Oh, I have done some other streams about AI and in one of them I created a diagram. I think it was this one. Maybe this one. This is the No, this is not the one. Sorry. No, this is not the the one I'm looking for. I think is this one scaled. Yeah, this isn't the diagram I was looking for. So, we have here the different building blocks which are the abilities API, MCP adapter and PHP AI SDK. The abilities API is the layer that allows purpose to publish the features it has so external agents can know what our WordPress can do. This is an API that can be used from external agents but also from internal plugins and from internal features such as the the common for. They can be published or they can be made public via an MCP adapter which will make that with an MCP agent. We can communicate with our WordPress and we can al some of the tools our WordPress has to offer and those tools will be the abilities um automatically converted into tools by the MCB adapter. So this is one angle from which our WordPress can use AI or how LLM um models can LLM are large language models. how LLMs can communicate with other workers um via MCP and can run tools defined as abilities but also our workers can communicate with external models. This is it can call models to perform actions. For example, we can summarize content. We can create images from prompts. We can do all of that. We can convert our WordPress instance into a into an AI agent that can do can do stuff. And in order to do that, we have this layer which is the PHP AI SDK which is what we are going to explore today. So via this layer or this um plug-in we this is like a a proxy is an intermediate layer that we can use to communicate with the with the outer space. We can communicate with models such as Gemini, Sonnet. We can communicate with different models and we can ask them to do things uh through this uh proxy and this will normalize the typical actions. So yeah, let's um have a look at this uh repository. Okay. So first we have this presentation like the official presentation of the project which was done on like last summer July uh 2025. Okay. So let's uh let's read a little bit about this. So it says the PHP AI client SDK provides shared infrastructure that lets WordPress plugins and all the PHP projects integrate AI capabilities rapidly and flexibly. So what we will do today is create a plugin that uses this um this thing that I think is shared in the form of a plugin. Let me see. Is this a plugin? No, it's um it's a composer package. So, we need to we need to create a plugin. install this package as a dependency. It's a composer dependency of our plug-in and then we need to call it using the name space WordPress AI client. Um, okay. Let's continue reading. Similar to projects like the Bersel AI SDK, it offers a unite interface that works across all AI providers from simple text generation to complex multimodel operations, streaming responses, and long running tasks. Okay. 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 the site. So one thing we will need to do is to introduce all credentials and this is something that in theory this plug-in h manages. Let me open another version of this. Um, okay. Um I want to come here from here say deep. Let's ask questions like for example um how do you how do I use this project in a plug-in and also okay that I guess it's by um yeah We Okay, perfect. So, we install this as a dependency and then we just um use the name space so we can make calls to the specific specific uh methods. Okay, it has two ways but then also um okay the different providers require a specific API key. How are these credentials entered if I use this package directly from a plugin? Okay. So if I define a specific environment variables then the plug-in automatically detects them. Mhm. Um okay. Or we can also depending on the we need to use different providers and they can be open AAI, Google provider, anthropic provider. For example, we we're going to do some tests just with one provider. So we can do um registry new provider registry and then we okay so I guess the easiest way is this one plugin implementation example here's how to implement this in a WordPress plug-in so we uh in your plug-in bootstrap file we do is we um set credential from plug-in options or okay from plug-in options alth config. So yeah, so the idea is that in our plug-in we create like a panel where the the user can introduce the API key and if uh that doesn't exist in our case we directly um define that. So we can simplify this in our in our example just by saying this you can check if a provider is configured using is provider code provider registry and model discovery. interesting but yeah let's continue with the okay so the credentials uh thing are clear and let's continue the SDK addresses both user needs and developer needs a provider agnostic approach puts the user first and the WordPress site administrators choose which provider and or model they want to configure and use. They can provide API credentials in a single place. Any plugins with AI features just work. No more vendor locking. Okay. So the way it works is that there is a panel where the credentials are introduced and then the the the calls that are done via this plug-in they just work even if we change models and I think it has some we can check that later. I think it has some logic to decide which model is the um the best option depending on the depending on the task to do. So yeah, we'll check this later. Developers can focus on building AI features, not AI infrastructure. Instead of trying to find an an official 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 plugins technical plumping. No more reinventing the web. Yeah. So this is like a central layer that um provides all the plumbing. So plug-in developers can directly use AI features. They don't need to worry about the specific calls that uh need to be made to the final uh model. They can just do things like this like I client prompt whatever. Okay. How it works? The API adapts to different developer needs. Some plug-in solutions may require specific models while others just need any text complication capability. The PHP AI client is the handles all the complexity behind the scenes different authentication methods, API formats, streaming protocols and provider that works all work through the same clean interface. So here's a simple tentative code example for generating text using a specific mode. Okay, but in the same example but written in a model and provider agnostic way and this can use uh behind the curtains. This can use like any model define the problem it solves. Uh today every WordPress plug-in 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 plug-in 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 today are for other tech stacks that are not interoperable with general PHP projects. either different serverside languages like the burcell versel AI SDK for nodes or a specific platforms like Drupal's AI module. So the PHPI client SDK centralizes this complexity for the PHP ecosystem and in WordPress WordPress specifically one integration point handle all providers one credential system serves all plugins providers update or new ones emerge. The changes happen once and benefit everyone. The architecture is designed with latest trends like multimodel first in mind and even anticipates future shifts like client side or browser based AI. Yeah, I'm really interested in this. Uh I think right now this is not this is not um it's not implemented. Um, let's talk a little bit about this. So, okay. So, for example, there are browsers like Chrome. So there are browsers like Chrome that they provide a built-in AI capabilities AI internal models at least they provide specific features that run um with AI internally like they have different APIs, summarizer, grader, proof reader, translator API, prompt API and this is interesting because this architecture is designed uh anticipating future ships like client side or browser based AI. But I think right now this is not possible because the current implementations that we have are only for these uh three providers which means we can only um communicate right now with uh models of these companies. But I guess that the idea is that we can define our own providers or we can submit a pull request with a new provider that um would enable the communication with a browserbased AI. That would be an interesting an interesting future. Okay. Build together. So 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 for with the wider PHP community. So I think that it refers to Yeah, that's why it's called PHP AI client because it's not really a specific to WordPress is a provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API. So this is not a specific for WordPress. This is something that can be used in any PHP project. We have here a provider agnostic uh PHP AI client SDK to communicate with yeah but can be can be installed as a composer package and in a plug-in WordPress in a WordPress plugin but it's not a plug-in itself. Okay. While this project is stewarded by the WordPress AI team members and contributors, it is technically WordPress agnostic. The gap the project addresses is relevant for not only the WordPress ecosystem but overall PHP ecosystem. So any PHP project could benefit from it. There's also no technical reason to scop it to WordPress as communicating with AI models and their providers is independent of WordPress built in APIs and par paradigms. Okay. Nice. Nice. This is uh more clear to me now. But this package that's why there are like a building blocks. we have like different uh ports. 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. Um, okay. So I understand this part. This is completely this project but um I'm not sure about this part. So the PHP maybe this has evolved because this was this was the intention in July last year and maybe this has evolved in some other thing. Um but yeah, let's uh read a bit more to see. Um let's ask uh Deep Wiki about this. Um, let's ask deep wiki about this. Um, are there any references in the repository about this other package that is more specific to WordPress? Let's see. So yeah, maybe this refers to the I think this may be the AI experiments plugin. This one. Um, this uh project is the WordPress. I think it's this one. I think it's this one because this provides a live demo. Let's try this. I think this provides a specific um dashboard to enter the the credentials. EI experiments. Okay. Most experiments require the valid AI credentials to function properly. To ensure those work properly, you need to have one or more AI credentials set here. So this is an example of how we can introduce these uh credentials, this API key. control whether AI experiments are enabled for your site disabled all experiments. Okay. And then once we have the credentials, we can enable experiments. And the experiments can be any of these ones that um they use this um package. In fact, if we go here to composer.json, application. We should see somewhere. Yeah, here it is. WordPress wpai client. This is the one. Go to composer.json. Yeah, WordPress PHP AI client. And then let's also check Let's also check this WordPress AI client AI clients. So includes abilities image. Okay. I think this has evolved. This has changed. Maybe the name space now is this one with underscore. Um, okay. This is um yeah, I think there are some inconsistencies here because the spaces in different but yeah um it confirms what we suspected. It uses the this SDK. Okay. So I would say that this um is the um I'm going to we can copy this. So here this um this refers to the PHP AI client. PHP AI client. And this refers to the um WordPress AI. WordPress AI which is the WordPress AI um experiments. This is this is my understanding at least. So um WordPress AI experiments and then this is like the PHP AI client SDK. I like this name. I like this thing. Um well this is not exactly true. I think what I think is the initially the idea was to create two composer packages but this is actually a plug-in right yeah AI PHP so I think the second part has evolved yeah plugin The second part has evolved as a plugin. I'm going to add here um this has evolved as a plugin. Um, I'm going to put here plugin and the background want to be here. This and This I want it to be here. This. Okay. So, this is a plugin and this is a composer package. Mhm. composer package and well this has evolved as a plug. Okay, I'm clarifying this because it says here that um because it said here that it consists on two composer packages. I think I initially that was the idea but um this has evolved in different things. Okay, let's continue reading here. 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 lower level projects such as um WPCLI integration. While also available as a plug-in for testing, these composter packages are the official adoption path. So does this uh includes a composer package composer.json. Ah so this is also a WordPress package and AI experiments and capabilities for WordPress. Okay. So maybe I need to see an example of Okay. So So yeah, maybe this is also um a composer um package. So instead of um went to also available as a plugin. So what I'm going to do here is compose a package. I need to check this. I need to check if this can be used only as a composer package. But yeah, we can use definitely this as a plug-in the experiments that internally it uh uses this um AI client as a composer package. Okay. So, let's uh let's try this. Let's create some code. I'm going to I'm going to create a new project under um um projects um 2026 um PHP PHP AI client demo string. What this uh doesn't exist. So what I need to do is um take this will create this project and will take me the PHP AI client SDK no uh demo stream. Okay. And now um let's open cursor um and let's um open the console. And what we can do is maybe open clo so it can generate So it can generate. So we can maybe do plot and I can say I can say PHP AI client. Okay. I can say scaffold a very basic structure of a WordPress plug-in. I want to test this composer package with some basic code to connect to external models from my WordPress instance. Okay. So we have this here um okay it's with um was another key and this is what I said scaffold Okay. So, I just wanted to maybe create a composer.json and um Okay. What I want you to do um No. Okay, I just want a basic plug-in structure to check the referenced uh composer package. You have some WordPress develop development skills. So, please use them to scaffold this basic plug-in structure. because I have some um have some skills. Let's open here in the meantime clo. As you can see here, I have some skills related to But it doesn't seem that. Yeah. So the thing is that this um extension of visual code or cursor doesn't really has access doesn't really have access to the skills. I let me check. Do you have access to the skills? It doesn't work as well as the terminal thing. So I may use this or here instead. But anyway, it it's creating the it's creating the PHP file for the plugin is creating composer.json is within the admin which I don't know exactly why. Let's see. Okay. No, I don't like um Okay. Create a very basic plug-in structure to test the composer package that is in the following repository. I want the plug-in to be really really basic. Any settings or any value I will define them via code. So please do not implement any settings page or dashboard or similar. Also, please do not implement any life cycle plug-in logic because this is just a test and I want the plug-in to be really basic. And um this is the and this is the repository. Copy link address. Let's see what it does. Um Okay, the thing is that I have defined to use always the context 7 MCP which um gets documentation directly. Also do not forget that you have a development WordPress development skills. So please use them for this work. Mhm. Okay. So, it's um it's checking the repository. I told it I want to check. So, it's creating a Um, okay. Nice. So, besides creating the Okay, nice. Nice. I think it was worth the the wait. Okay. So here we are using the the name space in order to do that is loading the autoload. Yeah, this is more or less what I wanted. Um, we need to uh simply test functions generate text using AI error lock return text. Okay. So we have these functions. So test AI text generation is uh doing this and it's returning the text but uh this function need to be called uh from somewhere. So maybe I can just do from init. This can be instead of calling directly this, this can be a function h where I call this and I um I lock this maybe that can be that can be a thing. Um, also what I'm going to do is to um Okay. Yes. Okay. I also prepare the plug-in. So credentials can be defined from a separate file inside the project. Okay, it's solving some issues because the version is PHP AI client. Let's see. It's 040 3 days ago. Okay, it's running composer install. Uh, which means is creating the vendor and inside the vendor composer. Okay, seems like a seems like a minimal uh setup which is what we were looking for. And then the PHPA AI client will internally have some other dependencies such as PHP HTTP I guess and some others. Um okay so now it's checking from the repository how the credential system works. Um in our case in vendor I know this is the vendor inside. So the credentials um I need credentials in order to run this. And in the meantime, what I can do is I'm going to open studio. I'm going to open studio. Maybe I can leverage I can use the same repository or 2026 experiments. Okay, let's use this. And in order to do this, I'm going to click it term because in WP content uh plugins I'm going to remove. And what I'm going to do is I'm going to link I'm going to create a sim link to the uh let me make this bigger. Okay. I'm going to ln uh project um cheese. Perfect. So if we run this, we should get this plug-in installed. Okay, define. Perfect. This is what I wanted because I want this to be credentials because I want to do this in another uh window in a different place. Oh, bear with me. I need to I need to move this to another folder. And from here I'm going to use open AI credentials and I need to access my open AI. Okay, it's this one. Then if I edit this open AI key. Perfect. Okay. So now we should have the credentials and what I'm going to do is um I'm going to close this because I want to open this in cursor which is the whole um WordPress installation that includes I'm going to be working on this on this file. Why do I want this? Because I want the the backlog to display the log. So if I reload um in WordPress settings online 560 Next thing include once plugin Okay, I think I need to go to plugins. Okay, so I shouldn't get this error message. Well, okay. It seems that um it shouldn't happen because if I remove the folder, I think that I should get I should get um the plugin should be removed. Um, so what I'm going to do is I'm going to stop the side. Going to remove this. Then I'm going to start again the side. And I'm going to um to log again. I need to get the password from here. So, it's so I'm logging in. Okay. I guess that's the first time. But now if I reload, I don't get this. Okay. And now that the backlog is uh clean again. So now we have the plugin installed. We have the credentials in place. And what we want is um okay so we have different functions simple test function to generate text using AI. Okay, let me try one thing. I'm going to try I'm going to try I'm going to try accessing the let me if I go to GitHub and if I go to my guests I have here. Um I have here uh yeah this one. Okay. WP shell is the command I was looking for. So if I do not from here but from DolbyP like uh 2026 experiments. If I open a terminal and I do WP shell, I get a terminal. um where my WordPress instance is loaded, which means that I should be able to access this. For example, in my example, I was doing this. So test AI text generation in my code doesn't require any parameters. Let's see. Because I think I forgot one thing. I forgot to activate this. Okay, let's start again. No models found that support text generation for this prompt. So the function is working properly. But uh something is going on here. Let's try the other functions just to see. Uh this is the one no models found for provider. So yeah. Um okay found with parameters. Okay. Okay. Well, but at least the testing setup is is there. Now, we need to fine-tune this function. So, um Okay. So, what I'm going to do is I'm going to remove all of them. And now we can check the documentation. Now, we can come here and we can test um called examples text generation using any compatible model from a specific provider. So this is the using provider open AI. Um So yeah, I actually like this structor. I like it. Yeah. Text. This is the And if not, I'm getting here the um the locks. So let's start again. Um Dolby VP shell test AI text generation. Test AI tech generation. No models found for provider open AI. Okay. Text generation using any compatible model from a specific provider. But in theory, generate text should um this should work with any compatible. So in theory, I shouldn't need to do this. Um So what I'm going to do is I'm going to ask the deep wiki thing which is here. Um, yeah, this PHP AI client. So, I'm going to open a new Let's see what can it tell me about this error. Okay, I'm going to also provide the function and this is my code. So it said Uh, so I need to do more things. Um, Requirements for success. For automatic discovery to work, you need at least one provider properly configured. Happy keys. Set environment variables. So we need to check first if this is configured. So um error rock is conf. Okay. Open AI and the backlog is empty. Okay. Because No, it should fail. Let's um test this again. Okay. So maybe the credentials. No, the credentials are uh properly properly introduced because his credentials, right? Credentials. um file exist. Um what I can do. What I can do is um Okay. Okay. We're fine. Okay. So if I go to shell. So the file is being properly loaded because this is something I just added and And let me see if the way the credentials are defined is correct. So if we go to PHP AI client and let's look for open open AI happy Okay. Mhm. Open AI. Okay. So maybe this is not the way to define the credentials. Um okay, let's look for healing docs. Um architecture requirements requirements Um, let's look for credentials. Um, Okay. All our credentials provided to the different providers. So what I have done is I have defined this constant called open AAI API key. But um Is it enough if I just do this before calling the PHP AI client SDK classes and methods. Okay, let's see. So be my AP key, my my real API key. Mhm. Um, so the API key is defined. If Okay, let's try again. This open AI is not configured. So that's the issue. That's the issue. Um, the boss Okay, I have the open AI API\_key constant defined before calling the methods like this. But the following cold returns false. So yeah something is going on. We have defined the constant. So in theory it should be it should be well actually you know what we can check how it's done here okay so so Maybe the API. Yeah, maybe the API key is not um maybe my API key is not um maybe my API key is not um okay, let's try another one. this one. Um, okay, let's try another one. because I think it I think it runs a specific API call. So I was I was expecting that um I could get an error message saying that your credentials are not correct. So I know that the the flow is working properly like the proper calls, the proper functions are being called. But no, it seems that my API key um because I have uh have several versions of the API key. So maybe it's not the the latest one. So let's try another one. Let's try another one. What I'm going to do is I'm going to define I'm going to define I'm going to define um let's check now if the anthropic is properly configured. Okay, let's start again. Let's go with uh WP shell traffic is not configured. No models found that support text generation for this prompt. Let's check. So I have uh don't they have the model? Okay. I'm going to test the So I'm getting this errors all the time. I have tried two API keys and I think that they are fine. So I don't think it's an issue with the wrong API key. Can you double check with the following repository how credentials should be defined in order to use these methods of the PHP AI client SDK? Um, Okay, let me access the prompt that I want to pass. I want to pass to code. Sorry. And in the meantime, we can check the we can check the AI. this one. And what we can also do is we can come here and say uh deep wiki for this. How are credentials managed in this project? I want a clear reference of how to provide credentials to use PHP AI client SDK functions. Okay. So, it's managed internally. Credentials are are stored internally uh as valid AI credentials. Check if any prompt test is supported for text generation. Okay. So, yeah. I don't know. Maybe the credentials I'm using are not fine. Um, Baby. Okay. Um Okay. So the credentials are correct. I have just tested them with an API call. Um, so lot credential ial the credentials are required are defined. So yeah at this point the API key should be defined and should be available. I'm not sure what's going on here. Um, Um, Okay, so I need to Let me try something. I'm going to try. So, do I need to initialize this? Um, do I need to initialize AI client in it. I'm not sure. But let's try this again. Uh, so in theory with this I get Um, I can go here to And now I have an error. Mhm. Okay, I'm getting an error because I'm getting this. And if I go to the book lock, okay, I think it was because let me remove the logs. Then I'm going to check the code. Do I have to? No, I only have to. What in it? Function AI client in it. That's fine because I'm doing this um Um, okay. For now, I'm going to comment this. Let's see what happens. Okay, with this if I go to plugins If I go to tools uh to plugins okay so we have the composer require WordPress AI client. This loads properly. Class exist. So I'm going to add here error lock AI client initialized. Let me see if I go to the backlog. A class WordPress AI client. AI client not found Um, if I go here, this a thing. AI client in it. Okay, let's ask a little bit more. Is there an init method that I can use to initialize the WordPress AI client that enables um a specific dashboard to enter the AI client credentials. Mhm. Okay. So that's true. Um, this is documented here. AI credentials dashboard. Not really documented here, but it's interesting to know. So this is correct. And now The only thing I need to Okay. You need else. Let's reload. AI client not initialized because Um, I client not initialized. Um Um, what's uh wrong here? And with this, I think we can call it a day. Let's see if we can finish the stream with uh this uh function working. It shouldn't be so difficult. Okay. I think I'm going to leave it here, but um next week I will do a second part of this because I want to really I want to really uh move forward with this and being able of um calling this uh function successfully. Okay. So, yeah, not a very successful stream, but we have explored a few things. We have learned a new things, which is always good. And yeah, hope you have you have enjoyed watching me struggling while I try to figure out how to talk things. So, yeah, have a great weekend and see you next week. uh same day, same time on Fridays at around um 5 uh p.m. set. Anyway, I I share the the specific time with the time zone outline. So, yeah, see you next week. Have a great weekend., PHP AI Client SDK, YouTube, 01kfrk904gmpkk87arjb0dmx18.