{"id":13982457,"url":"https://github.com/SoftCreatR/php-mistral-ai-sdk","last_synced_at":"2025-07-21T22:31:47.883Z","repository":{"id":220625819,"uuid":"752139629","full_name":"SoftCreatR/php-mistral-ai-sdk","owner":"SoftCreatR","description":"A powerful and easy-to-use PHP SDK for the Mistral AI API, allowing seamless integration of advanced AI-powered features into your PHP projects.","archived":false,"fork":false,"pushed_at":"2025-03-26T08:13:19.000Z","size":56,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-04T21:02:22.094Z","etag":null,"topics":["ai","api","api-client","api-wrapper","artificial-intelligence","gpt","gpt-3","gpt-4","hacktoberfest","llama","machine-learning","mistral","natural-language-processing","nlp","perplexity","php","replit","sdk"],"latest_commit_sha":null,"homepage":"https://docs.mistral.ai","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoftCreatR.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"softcreatr","custom":["https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4"]}},"created_at":"2024-02-03T06:16:48.000Z","updated_at":"2025-05-23T16:19:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"fb48df4a-10e2-42c9-92e1-1c087079d61c","html_url":"https://github.com/SoftCreatR/php-mistral-ai-sdk","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"c81898913958bc60a235c9b234c6a596d146ef77"},"previous_names":["softcreatr/php-mistral-ai-sdk"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/SoftCreatR/php-mistral-ai-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-mistral-ai-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-mistral-ai-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-mistral-ai-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-mistral-ai-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoftCreatR","download_url":"https://codeload.github.com/SoftCreatR/php-mistral-ai-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCreatR%2Fphp-mistral-ai-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264502649,"owners_count":23618664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","api-client","api-wrapper","artificial-intelligence","gpt","gpt-3","gpt-4","hacktoberfest","llama","machine-learning","mistral","natural-language-processing","nlp","perplexity","php","replit","sdk"],"created_at":"2024-08-09T05:01:22.265Z","updated_at":"2025-07-21T22:31:47.860Z","avatar_url":"https://github.com/SoftCreatR.png","language":"PHP","readme":"# Mistral API Wrapper for PHP\n\n[![Build](https://img.shields.io/github/actions/workflow/status/SoftCreatR/php-mistral-ai-sdk/.github/workflows/create-release.yml?branch=main)](https://github.com/SoftCreatR/php-mistral-ai-sdk/actions/workflows/create-release.yml) [![Latest Release](https://img.shields.io/packagist/v/SoftCreatR/php-mistral-ai-sdk?color=blue\u0026label=Latest%20Release)](https://packagist.org/packages/softcreatr/php-mistral-ai-sdk) [![ISC licensed](https://img.shields.io/badge/license-ISC-blue.svg)](./LICENSE.md) [![Plant Tree](https://img.shields.io/badge/dynamic/json?color=brightgreen\u0026label=Plant%20Tree\u0026query=%24.total\u0026url=https%3A%2F%2Fpublic.ecologi.com%2Fusers%2Fsoftcreatr%2Ftrees)](https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4) [![Codecov branch](https://img.shields.io/codecov/c/github/SoftCreatR/php-mistral-ai-sdk)](https://codecov.io/gh/SoftCreatR/php-mistral-ai-sdk) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/SoftCreatR/php-mistral-ai-sdk)](https://codeclimate.com/github/SoftCreatR/php-mistral-ai-sdk)\n\nThis PHP library provides a simple wrapper for the Mistral API, allowing you to easily integrate the Mistral API into your PHP projects.\n\n## Features\n\n-   Easy integration with Mistral API\n-   Supports all Mistral API endpoints\n-   Streaming support for real-time responses in chat completions\n-   Utilizes PSR-17 and PSR-18 compliant HTTP clients and factories for making API requests\n\n## Requirements\n\n-   PHP 8.1 or higher\n-   A PSR-17 HTTP Factory implementation (e.g., [guzzle/psr7](https://github.com/guzzle/psr7) or [nyholm/psr7](https://github.com/Nyholm/psr7))\n-   A PSR-18 HTTP Client implementation (e.g., [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) or [symfony/http-client](https://github.com/symfony/http-client))\n\n## Installation\n\nYou can install the library via [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require softcreatr/php-mistral-ai-sdk\n```\n\n## Usage\n\nFirst, include the library in your project:\n\n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n```\n\nThen, create an instance of the `MistralAI` class with your API key, organization (optional), an HTTP client, an HTTP request factory, and an HTTP stream factory:\n\n```php\nuse SoftCreatR\\MistralAI\\MistralAI;\n\n$apiKey = 'your_api_key';\n\n// Replace these lines with your chosen PSR-17 and PSR-18 compatible HTTP client and factories\n$httpClient = new YourChosenHttpClient();\n$requestFactory = new YourChosenRequestFactory();\n$streamFactory = new YourChosenStreamFactory();\n$uriFactory = new YourChosenUriFactory();\n\n$mistral = new MistralAI($requestFactory, $streamFactory, $uriFactory, $httpClient, $apiKey);\n```\n\nNow you can call any supported MistralAI API endpoint using the magic method `__call`:\n\n```php\n$response = $mistral-\u003ecreateChatCompletion([\n    'model' =\u003e 'mistral-tiny',\n    'messages' =\u003e [\n        [\n            'role' =\u003e 'user',\n            'content' =\u003e 'Who is the most renowned French painter?'\n        ],\n    ],\n]);\n\n// Process the API response\nif ($response-\u003egetStatusCode() === 200) {\n    $responseObj = json_decode($response-\u003egetBody()-\u003egetContents(), true);\n    \n    print_r($responseObj);\n} else {\n    echo \"Error: \" . $response-\u003egetStatusCode();\n}\n```\n\n### Streaming Example\n\nYou can enable real-time streaming for chat completions:\n\n```php\n$streamCallback = static function ($data) {\n    if (isset($data['choices'][0]['delta']['content'])) {\n        echo $data['choices'][0]['delta']['content'];\n    }\n};\n\n$mistral-\u003ecreateChatCompletion([\n    'model' =\u003e 'mistral-small-latest',\n    'messages' =\u003e [\n        [\n            'role' =\u003e 'user',\n            'content' =\u003e 'Tell me a story about a brave knight.',\n        ],\n    ],\n    'stream' =\u003e true,\n], $streamCallback);\n```\n\nFor more details on how to use each endpoint, refer to the [Mistral API documentation](https://docs.mistral.ai), and the [examples](https://github.com/SoftCreatR/php-mistral-ai-sdk/tree/main/examples) provided in the repository.\n\n## Supported Methods\n\n### Chat Completions\n-   [Create Chat Completion](https://docs.mistral.ai/api/#tag/chat/operation/chat_completion_v1_chat_completions_post) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/chat/createChatCompletion.php)\n    -   `createChatCompletion(array $options = [], callable $streamCallback = null)`\n\n### Embeddings\n-   [Create Embedding](https://docs.mistral.ai/api/#tag/embeddings/operation/embeddings_v1_embeddings_post) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/embeddings/createEmbedding.php)\n    -   `createEmbedding(array $options = [])`\n\n### Models\n-   [List Models](https://docs.mistral.ai/api/#tag/models/operation/list_models_v1_models_get) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/models/listModels.php)\n    -   `listModels()`\n-   [Retrieve Model](https://docs.mistral.ai/api/#tag/models/operation/retrieve_model_v1_models__model_id__get) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/models/retrieveModel.php)\n    -   `retrieveModel(array $parameters = [])`\n-   [Delete Model](https://docs.mistral.ai/api/#tag/models/operation/delete_model_v1_models__model_id__delete) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/models/deleteModel.php)\n    -   `deleteModel(array $parameters = [])`\n-   [Update Fine-Tuned Model](https://docs.mistral.ai/api/#tag/models/operation/jobs_api_routes_fine_tuning_update_fine_tuned_model) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/models/updateFineTunedModel.php)\n    -   `updateFineTunedModel(array $parameters = [])`\n-   [Archive Model](https://docs.mistral.ai/api/#tag/models/operation/jobs_api_routes_fine_tuning_archive_fine_tuned_model) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/models/archiveModel.php)\n    -   `archiveModel(array $parameters = [])`\n-   [Unarchive Model](https://docs.mistral.ai/api/#tag/models/operation/jobs_api_routes_fine_tuning_unarchive_fine_tuned_model) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/models/unarchiveModel.php)\n    -   `unarchiveModel(array $parameters = [])`\n\n### Files\n-   [Upload File](https://docs.mistral.ai/api/#tag/files/operation/files_api_routes_upload_file) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/files/uploadFile.php)\n    -   `uploadFile(array $options = [])`\n-   [List Files](https://docs.mistral.ai/api/#tag/files/operation/files_api_routes_list_files) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/files/listFiles.php)\n    -   `listFiles()`\n-   [Retrieve File](https://docs.mistral.ai/api/#tag/files/operation/files_api_routes_retrieve_file) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/files/retrieveFile.php)\n    -   `retrieveFile(array $parameters = [])`\n-   [Delete File](https://docs.mistral.ai/api/#tag/files/operation/files_api_routes_delete_file) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/files/deleteFile.php)\n    -   `deleteFile(array $parameters = [])`\n\n### Fine-Tuning Jobs\n-   [List Fine-Tuning Jobs](https://docs.mistral.ai/api/#tag/fine-tuning/operation/jobs_api_routes_fine_tuning_get_fine_tuning_jobs) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/finetuning/listFineTuningJobs.php)\n    -   `listFineTuningJobs()`\n-   [Retrieve Fine-Tuning Job](https://docs.mistral.ai/api/#tag/fine-tuning/operation/jobs_api_routes_fine_tuning_get_fine_tuning_job) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/finetuning/retrieveFineTuningJob.php)\n    -   `retrieveFineTuningJob(array $parameters = [])`\n-   [Cancel Fine-Tuning Job](https://docs.mistral.ai/api/#tag/fine-tuning/operation/jobs_api_routes_fine_tuning_cancel_fine_tuning_job) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/finetuning/cancelFineTuningJob.php)\n    -   `cancelFineTuningJob(array $parameters = [])`\n-   [Start Fine-Tuning Job](https://docs.mistral.ai/api/#tag/fine-tuning/operation/jobs_api_routes_fine_tuning_start_fine_tuning_job) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/finetuning/startFineTuningJob.php)\n    -   `startFineTuningJob(array $parameters = [])`\n-   [Create Fine-Tuning Job](https://docs.mistral.ai/api/#tag/fine-tuning/operation/jobs_api_routes_fine_tuning_create_fine_tuning_job) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/finetuning/createFineTuningJob.php)\n    -   `createFineTuningJob(array $options = [])`\n\n### FIM Completion\n-   [Create FIM Completion](https://docs.mistral.ai/api/#tag/fim/operation/fim_completion_v1_fim_completions_post) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/fim/createFimCompletion.php)\n    -   `createFimCompletion(array $options = [])`\n\n### Agents Completion\n-   [Create Agents Completion](https://docs.mistral.ai/api/#tag/agents/operation/agents_completion_v1_agents_completions_post) - [Example](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/examples/agents/createAgentsCompletion.php)\n    -   `createAgentsCompletion(array $options = [])`\n\n## Changelog\n\nFor a detailed list of changes and updates, please refer to the [CHANGELOG.md](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/CHANGELOG.md) file. We adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and document notable changes for each release.\n\n## Known Problems and Limitations\n\n### Streaming Support\nStreaming is now supported for real-time token generation in chat completions. Please make sure you are handling streams correctly using a callback, as demonstrated in the examples.\n\n## License\n\nThis library is licensed under the ISC License. See the [LICENSE](https://github.com/SoftCreatR/php-mistral-ai-sdk/blob/main/LICENSE.md) file for more information.\n\n## Maintainers 🛠️\n\n\u003ctable\u003e\n\u003ctr\u003e\n    \u003ctd style=\"text-align:center;word-wrap:break-word;width:150px;height: 150px\"\u003e\n        \u003ca href=https://github.com/SoftCreatR\u003e\n            \u003cimg src=https://avatars.githubusercontent.com/u/81188?v=4 width=\"100;\" alt=\"Sascha Greuel\"/\u003e\n            \u003cbr /\u003e\n            \u003csub style=\"font-size:14px\"\u003e\u003cb\u003eSascha Greuel\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Contributors ✨\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n","funding_links":["https://github.com/sponsors/softcreatr","https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4"],"categories":["LLMs \u0026 AI APIs","Table of Contents"],"sub_categories":["Recommended core stack","LLMs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSoftCreatR%2Fphp-mistral-ai-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSoftCreatR%2Fphp-mistral-ai-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSoftCreatR%2Fphp-mistral-ai-sdk/lists"}