PHPackages                             aisdk/mistral - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. aisdk/mistral

ActiveLibrary

aisdk/mistral
=============

Official Mistral provider for the PHP AI SDK.

v0.8.0(1mo ago)02MITPHPPHP ^8.3CI passing

Since Jul 15Pushed 1mo agoCompare

[ Source](https://github.com/phpaisdk/mistral)[ Packagist](https://packagist.org/packages/aisdk/mistral)[ Docs](https://github.com/phpaisdk/mistral)[ RSS](/packages/aisdk-mistral/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

aisdk/mistral
=============

[](#aisdkmistral)

[![GitHub Workflow Status](https://camo.githubusercontent.com/e0c17908509f160bbdd74a30229cb017a3201741e6017133203ed6375622aa51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706870616973646b2f6d69737472616c2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/phpaisdk/mistral/actions)[![Total Downloads](https://camo.githubusercontent.com/15625a1b8f29d9bf6f2767c3f4fd24002774a37b0ce8b2dc75b5696e1dc73e94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616973646b2f6d69737472616c)](https://packagist.org/packages/aisdk/mistral)[![Latest Version](https://camo.githubusercontent.com/1fd9f8b30b8f083ce3ee5869ab5bc5d59e3a0f1b074c72b2a434a026772be35a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973646b2f6d69737472616c)](https://packagist.org/packages/aisdk/mistral)[![License](https://camo.githubusercontent.com/2685059ccfcc2886340b5b79b15f8cd95a761c617ecc221c0c43ada43a10a1ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616973646b2f6d69737472616c)](https://packagist.org/packages/aisdk/mistral)[![Why PHP in 2026](https://camo.githubusercontent.com/d2b9305e630caf7daae4ca023de39ece0b885c37461629d42961533f00868b76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5768795f5048502d696e5f323032362d3741383645383f7374796c653d666c61742d737175617265266c6162656c436f6c6f723d313831383162)](https://whyphp.dev)

---

Official Mistral provider for the PHP AI SDK. Uses Mistral's OpenAI-compatible Chat Completions API and embeddings endpoint.

Installation
------------

[](#installation)

```
composer require aisdk/mistral
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Generate;
use AiSdk\Mistral;

$result = Generate::text()
    ->model(Mistral::model('mistral-large-latest'))
    ->instructions('Write short, clear answers.')
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
```

Default model shorthand:

```
Generate::model(Mistral::model('mistral-large-latest'));

$result = Generate::text('Explain closures in PHP.')->run();
```

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

VariableDescriptionDefault`MISTRAL_API_KEY`API key for authenticationRequired`MISTRAL_BASE_URL`Base URL for API requests`https://api.mistral.ai/v1`### Programmatic Configuration

[](#programmatic-configuration)

```
$provider = Mistral::create([
    'apiKey' => 'mistral-...',
    'baseUrl' => 'https://api.mistral.ai/v1',
    'headers' => ['X-Custom-Header' => 'value'],
]);
```

Supported Capabilities
----------------------

[](#supported-capabilities)

CapabilitySupportText generationNativeStreamingNativeTool callingNativeStructured outputAdapted (`json_object` + instruction); exact native support can be declared at runtimeEmbeddingsNativeText inputNativeImage inputSupported by the adapter; the selected model is validated by MistralStreaming
---------

[](#streaming)

```
use AiSdk\Generate;
use AiSdk\Mistral;

$stream = Generate::text('Tell me a story.')
    ->model(Mistral::model('mistral-large-latest'))
    ->stream();

foreach ($stream->chunks() as $chunk) {
    echo $chunk;
}

$result = $stream->run();
```

Embeddings
----------

[](#embeddings)

```
use AiSdk\Generate;
use AiSdk\Mistral;

$result = Generate::embedding(['Search query', 'Document text'])
    ->model(Mistral::model('mistral-embed'))
    ->providerOptions('mistral', ['user' => 'user-123'])
    ->run();

$queryVector = $result->embeddings[0]->vector;
$documentVector = $result->embeddings[1]->vector;
```

Mistral's embedding request schema does not expose a dimensions field, so this adapter rejects the portable `dimensions()` option before sending a request.

Structured Output
-----------------

[](#structured-output)

Without an exact runtime capability override, the provider adapter degrades `json_schema` to `json_object` with an injected JSON instruction:

```
use AiSdk\Generate;
use AiSdk\Mistral;
use AiSdk\Schema;

$result = Generate::text()
    ->model(Mistral::model('mistral-large-latest'))
    ->prompt('Extract the city and country from: Lahore, Pakistan.')
    ->output(Schema::object(
        name: 'address',
        properties: [
            Schema::string(name: 'city')->required(),
            Schema::string(name: 'country')->required(),
        ],
    ))
    ->run();
```

Models with native `json_schema` support (`openai/gpt-oss-20b`, `openai/gpt-oss-120b`, `moonshotai/kimi*`) use the native format directly.

Tools
-----

[](#tools)

```
use AiSdk\Generate;
use AiSdk\Mistral;
use AiSdk\Schema;
use AiSdk\Tool;

$weather = Tool::make('weather', 'Get current weather')
    ->input(Schema::string(name: 'city')->required())
    ->run(fn (string $city): string => "Sunny in {$city}");

$result = Generate::text()
    ->model(Mistral::model('mistral-large-latest'))
    ->prompt('What is the weather in Lahore?')
    ->tool($weather)
    ->run();
```

Model IDs and Capabilities
--------------------------

[](#model-ids-and-capabilities)

Mistral model IDs pass through unchanged and do not need to be registered. The package does not ship a model inventory; the Mistral API remains the authority on whether a particular model accepts a requested feature.

Capabilities describe what the Mistral adapter can serialize. The Mistral API returns a normalized SDK exception if the selected model or requested feature is rejected.

Provider-Specific Options
-------------------------

[](#provider-specific-options)

Raw provider options can be passed as an escape hatch:

```
$result = Generate::text('Hello')
    ->model(Mistral::model('mistral-large-latest'))
    ->providerOptions('mistral', [
        'raw' => ['top_k' => 40],
    ])
    ->run();
```

Testing
-------

[](#testing)

```
composer test
```

Documentation
-------------

[](#documentation)

- [PHP AI SDK documentation](https://phpaisdk.com/docs)
- [Mistral documentation](https://phpaisdk.com/docs/mistral)

Community
---------

[](#community)

- [Contributing](https://github.com/phpaisdk/.github/blob/main/CONTRIBUTING.md)
- [Support](https://github.com/phpaisdk/.github/blob/main/SUPPORT.md)
- For private security reports, email .

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef29d1962da41e7526023f215cf844494e209b2fd163742084cb919a3b508021?d=identicon)[aisdk](/maintainers/aisdk)

---

Top Contributors

[![RanaMoizHaider](https://avatars.githubusercontent.com/u/58527494?v=4)](https://github.com/RanaMoizHaider "RanaMoizHaider (3 commits)")

---

Tags

aillmmistralopenai-compatibleaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aisdk-mistral/health.svg)

```
[![Health](https://phpackages.com/badges/aisdk-mistral/health.svg)](https://phpackages.com/packages/aisdk-mistral)
```

###  Alternatives

[ardagnsrn/ollama-php

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

208104.9k](/packages/ardagnsrn-ollama-php)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6877.8k](/packages/sbsaga-toon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
