Overview

Drive Copilot from PHP – the same provider stack the Panel uses, available to CLI commands, hooks, and custom workflows.

Generate AI content from PHP – CLI commands, hooks, custom controllers, sister plugins like Content Translator. The same provider stack the Panel uses, exposed as a public API.

Available since v3.8. The Panel proxy is unchanged – this PHP API gives you direct access to the same provider transports.

Components

Client

The entry point. One method call generates text or structured JSON via your configured provider.

Providers

One transport per AI provider: OpenAI, Anthropic, Gemini, Mistral. Switch providers via config – your call sites stay the same.

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.

Continue with the Client reference for instance vs. singleton, error handling, and DI hooks.