Mainstay GitHub
All docs

AI connectors

Connect the AI providers laravel/ai speaks from one admin screen, and prompt them from your code.

Mainstay talks to AI providers through laravel/ai, so every provider it speaks is one a site can connect: OpenAI, Anthropic, Gemini, Mistral, Groq, xAI, DeepSeek, OpenRouter, Ollama and the rest. The admin's Connectors screen is open to whoever holds manage_connectors.

The screen

  • A card per provider: what it can do, read from the laravel/ai contracts it implements, and where its key comes from.

  • A password field that saves a key encrypted with APP_KEY in mainstay_connectors, never shown again.

  • Test, which asks the provider's cheapest model for one word, or embeds one, with the key kept out of any error it reports.

  • The provider each kind of work goes to: text, images, speech, transcription, embeddings, reranking and classification.

Where a key comes from

A key in the environment, under the name laravel/ai's config reads, ANTHROPIC_API_KEY or OPENAI_API_KEY, wins over one saved on the screen. A provider's other settings, a URL or a region, are laravel/ai's config:

php artisan vendor:publish --tag=ai-config

A queue worker reads the saved keys when it first prompts, so restart workers after changing one.

Prompting from your code

Code uses laravel/ai itself and reaches the provider the screen chose for that kind of work:

use Laravel\Ai\Image;

use function Laravel\Ai\agent;

$alt = agent('You write alt text of at most 120 characters.')
    ->prompt('A harbour at dusk, two boats.')
    ->text;

$poster = Image::of('A harbour at dusk, as a linocut')->generate();

A provider from a plugin

A plugin's providers() adds entries to laravel/ai's ai.providers, each with a label for the screen. One on a driver laravel/ai has is config alone; an openai-compatible one names its models, since they cannot be guessed:

public function providers(): array
{
    return [
        'together' => [
            'label' => 'Together AI',
            'driver' => 'openai-compatible',
            'url' => 'https://api.together.xyz/v1',
            'models' => ['text' => ['default' => 'meta-llama/Llama-3.3-70B-Instruct-Turbo']],
        ],
    ];
}

A driver of its own is a closure taking the application and the provider's config and returning a laravel/ai provider. Your own ai.providers entry of the same name wins key by key, so config/ai.php can give a plugin's provider a key from the environment.

Not built

There is no AI feature in the admin itself: the screen connects providers for your code and your plugins to use.