saarnilauri/ai-provider-for-mistral

Independent WordPress AI Client provider for Mistral. Works as both a Composer package and WordPress plugin.

Maintainers

Package info

github.com/saarnilauri/ai-provider-for-mistral

Type:wordpress-plugin

pkg:composer/saarnilauri/ai-provider-for-mistral

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 0

v1.0.2 2026-03-13 09:34 UTC

README

A third-party provider for Mistral in the PHP AI Client SDK. Works as both a Composer package and a WordPress plugin.

This project is independent and is not affiliated with, endorsed by, or sponsored by Mistral AI.

Requirements

Installation

As a Composer Package

composer require saarnilauri/ai-provider-for-mistral

The Composer distribution is intended for library usage and excludes plugin.php.

As a WordPress Plugin

  1. Download ai-provider-for-mistral.zip from GitHub Releases (do not use GitHub "Source code" archives)
  2. Upload the ZIP in WordPress admin via Plugins > Add New Plugin > Upload Plugin
  3. Ensure the PHP AI Client plugin is installed and activated
  4. Activate the plugin through the WordPress admin

Installing with WP-CLI

Use the release ZIP URL from GitHub Releases — not the auto-generated main.zip source archive, which is missing the bundled dependencies:

wp plugin install https://github.com/saarnilauri/ai-provider-for-mistral/releases/download/v1.0.1/ai-provider-for-mistral.zip --activate

Replace v1.0.1 with the desired release tag.

Building the Plugin ZIP

Build a distributable plugin archive locally:

make dist
# or:
./scripts/build-plugin-zip.sh

The ZIP is created at dist/ai-provider-for-mistral.zip and includes plugin.php.

Testing

Install development dependencies:

composer install

Run unit tests:

composer test
# or:
composer test:unit

Run integration tests (requires MISTRAL_API_KEY):

composer test:integration

Release Workflow

This repository includes a GitHub Actions workflow at .github/workflows/release-plugin-zip.yml:

  • On tag pushes matching v*, it builds dist/ai-provider-for-mistral.zip
  • For tagged releases, it derives the version from the tag (for example v0.1.0 -> 0.1.0) and validates committed metadata:
    • readme.txt Stable tag must match the tag version
    • plugin.php Version must match the tag version
  • If versions do not match, the workflow fails
  • It uploads the ZIP as a workflow artifact
  • It attaches the ZIP to the GitHub release for that tag

Usage

With WordPress

The provider automatically registers itself with the PHP AI Client on the init hook. Simply ensure both plugins are active and configure your API key:

// Set your Mistral API key (or use the MISTRAL_API_KEY environment variable)
putenv('MISTRAL_API_KEY=your-api-key');

// Use the provider
$result = AiClient::prompt('Hello, world!')
    ->usingProvider('mistral')
    ->generateTextResult();

As a Standalone Package

use WordPress\AiClient\AiClient;
use AiProviderForMistral\Provider\ProviderForMistral;

// Register the provider
$registry = AiClient::defaultRegistry();
$registry->registerProvider(ProviderForMistral::class);

// Set your API key
putenv('MISTRAL_API_KEY=your-api-key');

// Generate text
$result = AiClient::prompt('Explain quantum computing')
    ->usingProvider('mistral')
    ->generateTextResult();

echo $result->toText();

Image Generation

Mistral supports image generation through its Agents API. The provider handles the multi-step flow (agent creation, conversation, file download) automatically:

$result = AiClient::prompt('A red apple on a white background')
    ->usingProvider('mistral')
    ->generateImageResult();

// Get the generated image as base64-encoded PNG
$file = $result->getCandidates()[0]->getMessage()->getParts()[0]->getFile();
$binaryData = base64_decode($file->getBase64Data(), true);
file_put_contents('apple.png', $binaryData);

Supported Models

Available models are dynamically discovered from the Mistral API. This includes text models and, for compatible models, vision and function-calling capabilities. Image generation is supported through models like mistral-medium-2505. See the Mistral documentation for the full list of available models.

Configuration

The provider uses the MISTRAL_API_KEY environment variable for authentication. You can set this in your environment or via PHP:

putenv('MISTRAL_API_KEY=your-api-key');

License

GPL-2.0-or-later