{"id":29551022,"url":"https://github.com/wordpress/php-ai-client","last_synced_at":"2026-02-20T08:05:01.585Z","repository":{"id":299736143,"uuid":"1003991376","full_name":"WordPress/php-ai-client","owner":"WordPress","description":"A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.","archived":false,"fork":false,"pushed_at":"2026-02-05T20:23:57.000Z","size":2173,"stargazers_count":220,"open_issues_count":27,"forks_count":48,"subscribers_count":12,"default_branch":"trunk","last_synced_at":"2026-02-10T13:48:13.688Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WordPress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-06-18T00:38:37.000Z","updated_at":"2026-02-08T12:07:33.000Z","dependencies_parsed_at":"2026-02-17T01:00:33.198Z","dependency_job_id":null,"html_url":"https://github.com/WordPress/php-ai-client","commit_stats":null,"previous_names":["wordpress/php-ai-client"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/WordPress/php-ai-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WordPress%2Fphp-ai-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WordPress%2Fphp-ai-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WordPress%2Fphp-ai-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WordPress%2Fphp-ai-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WordPress","download_url":"https://codeload.github.com/WordPress/php-ai-client/tar.gz/refs/heads/trunk","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WordPress%2Fphp-ai-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29528226,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T00:57:22.232Z","status":"ssl_error","status_checked_at":"2026-02-17T00:54:25.811Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-18T04:01:39.226Z","updated_at":"2026-02-20T08:05:01.567Z","avatar_url":"https://github.com/WordPress.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP AI Client\n\n[_Part of the **AI Building Blocks for WordPress** initiative_](https://make.wordpress.org/ai/2025/07/17/ai-building-blocks)\n\nA provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.\n\n## General information\n\nThis 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.\n\nWhile 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.\n\n## Installation\n\n```\ncomposer require wordpress/php-ai-client\n```\n\n## Code examples\n\n### Text generation using a specific model\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$text = AiClient::prompt('Write a 2-verse poem about PHP.')\n    -\u003eusingModel(Google::model('gemini-2.5-flash'))\n    -\u003egenerateText();\n```\n\n### Text generation using any compatible model from a specific provider\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$text = AiClient::prompt('Write a 2-verse poem about PHP.')\n    -\u003eusingProvider('openai')\n    -\u003egenerateText();\n```\n\n### Text generation using any compatible model\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$text = AiClient::prompt('Write a 2-verse poem about PHP.')\n    -\u003egenerateText();\n```\n\n### Text generation with additional parameters\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$text = AiClient::prompt('Write a 2-verse poem about PHP.')\n    -\u003eusingSystemInstruction('You are a famous poet from the 17th century.')\n    -\u003eusingTemperature(0.8)\n    -\u003egenerateText();\n```\n\n### Text generation with multiple candidates using any compatible model\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$texts = AiClient::prompt('Write a 2-verse poem about PHP.')\n    -\u003egenerateTexts(4);\n```\n\n### Text generation using max tokens\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$text = AiClient::prompt('Write a 80-verse poem with long stanzas about PHP.')\n    -\u003eusingSystemInstruction('You are a famous poet from the 17th century.')\n    -\u003eusingTemperature(0.8)\n    -\u003eusingMaxTokens(8000);\n    -\u003egenerateText();\n```\n\n### Image generation using any compatible model\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n$imageFile = AiClient::prompt('Generate an illustration of the PHP elephant in the Caribbean sea.')\n    -\u003egenerateImage();\n```\n\nSee 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.\n\n**More documentation is coming soon.**\n\n## Event Dispatching\n\nThe 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.\n\n### Available Events\n\n- `BeforeGenerateResultEvent` - Dispatched before a prompt is sent to the model\n- `AfterGenerateResultEvent` - Dispatched after a result is received from the model\n\n**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.\n\n### Connecting Your Event Dispatcher\n\nTo enable event dispatching, pass any PSR-14 compatible `EventDispatcherInterface` to the client:\n\n```php\nuse WordPress\\AiClient\\AiClient;\n\n// Set your PSR-14 event dispatcher\nAiClient::setEventDispatcher($yourEventDispatcher);\n\n// Events will now be dispatched during generation\n$text = AiClient::prompt('Hello, world!')\n    -\u003egenerateText();\n```\n\n### Example: Logging Events\n\n```php\nuse WordPress\\AiClient\\Events\\BeforeGenerateResultEvent;\nuse WordPress\\AiClient\\Events\\AfterGenerateResultEvent;\n\n// In your event listener/subscriber\nclass AiEventListener\n{\n    public function onBeforeGenerate(BeforeGenerateResultEvent $event): void\n    {\n        $model = $event-\u003egetModel();\n        $messages = $event-\u003egetMessages();\n        $capability = $event-\u003egetCapability();\n\n        // Log, monitor, or perform other actions\n    }\n\n    public function onAfterGenerate(AfterGenerateResultEvent $event): void\n    {\n        $result = $event-\u003egetResult();\n\n        // Log the result, track usage, etc.\n    }\n}\n```\n\n## Further reading\n\nFor more information on the requirements and guiding principles, please review:\n\n* [Glossary](./docs/GLOSSARY.md)\n* [Requirements](./docs/REQUIREMENTS.md)\n* [Architecture](./docs/ARCHITECTURE.md)\n* [Prepublish Checklist](./docs/PREPUBLISH-CHECKLIST.md)\n\nSee the [contributing documentation](./CONTRIBUTING.md) for more information on how to get involved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwordpress%2Fphp-ai-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwordpress%2Fphp-ai-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwordpress%2Fphp-ai-client/lists"}