PHPackages                             partitech/php-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. [API Development](/categories/api)
4. /
5. partitech/php-mistral

ActiveLibrary[API Development](/categories/api)

partitech/php-mistral
=====================

Connect to Mistral | Anthropic | Xai | Hugging Face | LamaC++ | Vllm | Ollama

v0.1.29(1mo ago)2735.5k↓45.4%10[1 issues](https://github.com/partITech/php-mistral/issues)1MITPHPPHP &gt;=8.2

Since Jan 16Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/partITech/php-mistral)[ Packagist](https://packagist.org/packages/partitech/php-mistral)[ RSS](/packages/partitech-php-mistral/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (57)Versions (68)Used By (1)

PhpMistral
==========

[](#phpmistral)

Important

📖 **Official Documentation** is available here:
Make sure to visit for in-depth guides, examples, and advanced usage.

---

**PhpMistral** is an **open-source** PHP client designed to interact with various LLM inference servers (like Mistral, Hugging Face TGI, vLLM, Ollama, llama.cpp, xAI, and more), embedding servers, and Hugging Face datasets.
It provides a unified interface for chat completions (streaming &amp; non-streaming), embeddings (dense &amp; sparse), reranking, guided JSON generation, document generation, and Hugging Face dataset management.

Tip

Perfect for developers building AI-driven PHP applications: chatbots, document search, reranking, embeddings, or dataset management for finetuning.

---

🛠 PSR-18 Compatible HTTP Client
-------------------------------

[](#-psr-18-compatible-http-client)

**PhpMistral** has been fully refactored to comply with **PSR-18** recommendations (PHP Standards Recommendation for HTTP clients).
This means you can plug in **any HTTP client** that implements PSR-18, including:

- **Guzzle**
- **Symfony HttpClient**
- **cURL-based clients**
- **Buzz**
- Any other compliant client!

Important

The library does **not lock you** into any specific HTTP client. Choose the one that best fits your framework, performance needs, or preferences.
Whether you're using **Symfony**, **Laravel**, or a custom stack, PhpMistral integrates seamlessly into your environment.

This ensures **flexibility**, **interoperability**, and **future-proofing** of your PHP AI integrations.

---

Key Features
------------

[](#key-features)

- **Open-source**:
    - Free to use, modify, and contribute to.
- **Framework-agnostic**:
    - Compatible with any PHP framework (Laravel, Symfony, Slim, custom apps, etc.).
- **Multi-backend support**:
    - OpenAI, Mistral Platform, Hugging Face TGI, vLLM, Ollama, llama.cpp, xAI, and more.
- **Chat completions**:
    - Streaming and non-streaming interactions.
- **Embeddings**:
    - Dense embeddings and sparse embeddings (Splade pooling).
- **Reranking API**:
    - Compare and rank multiple documents based on a query.
- **Guided JSON generation**:
    - Ensure structured outputs based on a schema.
- **Document generation (Mistral)**:
    - Generate structured documents directly from models.
- **Pooling API (vLLM)**:
    - Efficient load balancing across multiple vLLM servers.
- **Hugging Face Dataset API**:
    - Seamlessly interact with Hugging Face datasets, list files, download, manage, and search datasets directly from PHP.
- **MCP (Model Context Protocol) support**:
    - Call external tools through MCP-compatible servers like Claude and docker-based or exec runners.
- **Recursion safety for tool calls**:
    - Avoid infinite loops with `setMcpMaxRecursion()`.

---

Supported Providers &amp; Features
----------------------------------

[](#supported-providers--features)

### Core Features

[](#core-features)

ProviderChat (stream)Chat (non-stream)EmbeddingsSparse EmbeddingsMistral Platform✅✅✅Hugging Face TGI✅✅✅vLLM✅✅✅Ollama✅✅✅llama.cpp✅✅✅xAI✅✅✅Text Embedding Inference✅✅Voyage✅### Advanced Features

[](#advanced-features)

ProviderRerankGuided JSONDocumentsPoolingHF DatasetsMistral Platform✅✅✅Hugging Face TGI✅✅✅vLLM✅✅✅Ollama✅✅llama.cpp✅✅xAI✅✅Text Embedding Inference✅Voyage✅---

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

[](#installation)

```
composer require partitech/php-mistral:^0.1
```

---

Example Usages
--------------

[](#example-usages)

### Chat Completion (Streaming)

[](#chat-completion-streaming)

```
$client = new MistralClient($apiKey);
$messages = $client->getMessages()->addUserMessage('What is the best French cheese?');

$params = [
    'model' => 'mistral-large-latest',
        'temperature' => 0.7,
        'top_p' => 1,
        'max_tokens' => null,
        'safe_prompt' => false,
        'random_seed' => 0
];

try {
    /** @var Message $chunk */
    foreach ($client->chat(messages: $messages, params: $params, stream: true) as $chunk) {
        echo $chunk->getChunk();
    }
} catch (MistralClientException|DateMalformedStringException $e) {
    echo $e->getMessage();
    exit(1);
}
```

### Dense Embedding

[](#dense-embedding)

```
use Partitech\PhpMistral\Clients\Tei\TeiClient;

$client = new TeiClient(apiKey: $apiKey, url: $embeddingUrl);
$embedding = $client->embed(inputs: "My name is Olivier and I");
```

### Sparse Embedding (Splade Pooling)

[](#sparse-embedding-splade-pooling)

```
$client = new TeiClient(apiKey: (string) $apiKey, url: $teiUrl);
$embedding = $client->embedSparse(inputs: 'What is Deep Learning?');
var_dump($embedding);
```

### Rerank

[](#rerank)

```
$client = new TeiClient(apiKey: $apiKey, url: $teiUrl);
$results = $client->rerank(
        query: 'What is the difference between Deep Learning and Machine Learning?',
        texts: [
            'Deep learning is...',
            'cheese is made of',
            'Deep Learning is not...'
        ]

    );
```

### Hugging Face Dataset Management

[](#hugging-face-dataset-management)

```
use Partitech\PhpMistral\Clients\HuggingFace\HuggingFaceDatasetClient;

$client = new HuggingFaceDatasetClient(apiKey: $apiKey);

// Commit large dataset to huggingface repository
$commit = $client->commit(
    repository: $hfUser . '/test2',
    dir: realpath('mon_dataset'),
    files: $client->listFiles('./dir'),
    summary: 'commit title',
    commitMessage: 'commit message',
    branch: 'main'
);

// get specific dataset page
$paginatedRows = $client->rows(
        dataset: 'nvidia/OpenCodeReasoning',
        split: 'split_0',
        config: 'split_0',
        offset: 3,
        length: 2
    );

// Download Dataset locally
$dest = $client->downloadDatasetFiles(
    'google/civil_comments',
    revision: 'main',
    destination: '/tmp/downloaded_datasets/civil_comments'
);
```

Tip

Combine **Hugging Face Datasets** with **Embeddings** and **Reranking** to build advanced search or finetuning pipelines directly in PHP.

---

Contributing
------------

[](#contributing)

**We welcome contributions!**
Help us make **PhpMistral** safer, richer, and more powerful.
Feel free to:

- Submit issues or ideas 💡
- Improve documentation 📚
- Add support for new providers or features 🚀
- Fix bugs 🐛

Important

Whether you're a beginner or an experienced developer, your help is valuable!
Join us in making **PhpMistral** the go-to PHP library for AI integrations.

---

License
-------

[](#license)

MIT License

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance87

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.9% 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

Every ~16 days

Recently: every ~32 days

Total

52

Last Release

59d ago

PHP version history (2 changes)v0.0.21PHP &gt;=8.3

v0.1.2PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/117969827?v=4)[partITech](/maintainers/partitech)[@partITech](https://github.com/partITech)

---

Top Contributors

[![GeraudBourdin](https://avatars.githubusercontent.com/u/9740283?v=4)](https://github.com/GeraudBourdin "GeraudBourdin (263 commits)")[![nicobleiler](https://avatars.githubusercontent.com/u/29607555?v=4)](https://github.com/nicobleiler "nicobleiler (5 commits)")[![partITech](https://avatars.githubusercontent.com/u/117969827?v=4)](https://github.com/partITech "partITech (4 commits)")[![BenLaKnet](https://avatars.githubusercontent.com/u/100009654?v=4)](https://github.com/BenLaKnet "BenLaKnet (3 commits)")[![petarbasic](https://avatars.githubusercontent.com/u/52317999?v=4)](https://github.com/petarbasic "petarbasic (3 commits)")[![FrdNcy](https://avatars.githubusercontent.com/u/26270686?v=4)](https://github.com/FrdNcy "FrdNcy (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k28.0M318](/packages/openai-php-client)[deeplcom/deepl-php

Official DeepL API Client Library

2607.3M114](/packages/deeplcom-deepl-php)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.9M50](/packages/getbrevo-brevo-php)[n1ebieski/ksef-php-client

PHP API client that allows you to interact with the API Krajowego Systemu e-Faktur

9067.8k](/packages/n1ebieski-ksef-php-client)[trycourier/courier

Courier PHP SDK

15660.9k](/packages/trycourier-courier)

PHPackages © 2026

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