Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Created March 31, 2026 13:28
Show Gist options
  • Select an option

  • Save niraj-shah/a2cd6536508ec331da693937bc2f65fe to your computer and use it in GitHub Desktop.

Select an option

Save niraj-shah/a2cd6536508ec331da693937bc2f65fe to your computer and use it in GitHub Desktop.
WordPress AI Client example
<?php
include 'vendor/autoload.php';
use WordPress\AiClient\AiClient;
use WordPress\GoogleAiProvider\Provider\GoogleProvider;
// 1. Set your API key securely
putenv('GOOGLE_API_KEY=YOUR-GOOGLE-AI-API-KEY');
// 2. Register the provider with the default registry
$registry = AiClient::defaultRegistry();
$registry->registerProvider(GoogleProvider::class);
// 3. Simple text generation
$result = AiClient::prompt('Write a short intro about PHP and AI.')
->usingProvider('google')
->usingModelPreference('gemini-2.5-flash')
->generateTextResult();
$Parsedown = new Parsedown();
// Convert and echo the rendered HTML
echo $Parsedown->text($result->toText());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment