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.
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.
Hosting & Troubleshooting
Fix the server problems the Agents view reports, from a subfolder install to a missing Authorization header, and read why an agent's write is refused or rate-limited.
Client
Generate text or structured JSON from any PHP context with one method call – CLI commands, hooks, custom controllers.