Overview
Drive Copilot from PHP – the same providers and credentials as the Panel, available to CLI commands, hooks, and custom workflows.
Two classes make up the surface: Client for one-call generation, plus the Provider transports for OpenAI, Anthropic, Gemini, and Mistral. Sister plugins like Content Translator consume Client directly.
Available since v3.8. The PHP API talks to the same providers as the Panel, without going through the Panel proxy.
Components
Minimal Example
use JohannSchopplich\Copilot\AI\Client;
$response = Client::instance()->generateObject(
messages: [
['role' => 'system', 'content' => 'You return JSON only.'],
['role' => 'user', 'content' => 'List three primary colors.'],
],
schema: [
'type' => 'object',
'properties' => [
'colors' => ['type' => 'array', 'items' => ['type' => 'string']],
],
'required' => ['colors'],
'additionalProperties' => false,
],
);
print_r($response['colors']);
The provider is selected from johannschopplich.copilot.provider. Switch providers without touching this code.