Overview

Drive Copilot from PHP – the same provider stack the Panel uses, 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 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.