Mistral open source license explained
Quick answer
The Mistral open source license is a permissive license allowing free use, modification, and distribution of the code and models with attribution. It typically requires compliance with conditions such as providing proper credit and not misrepresenting the origin. Check the official Mistral GitHub repository for the exact license text and terms.
PREREQUISITES
Python 3.8+pip install mistralai or openai>=1.0MISTRAL_API_KEY environment variable for API access
Setup
To use Mistral models via API, install the official mistralai Python SDK or use the OpenAI-compatible openai SDK with the base_url set to Mistral's endpoint. Set your API key in the environment variable MISTRAL_API_KEY.
pip install mistralai
# or for OpenAI-compatible usage
pip install openai>=1.0 Step by step
Here is a simple example to call the mistral-large-latest model using the official mistralai SDK. This example assumes you have set MISTRAL_API_KEY in your environment.
from mistralai import Mistral
import os
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
response = client.chat.completions.create(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Explain the Mistral open source license."}]
)
print(response.choices[0].message.content) output
The Mistral open source license allows free use, modification, and distribution of the models and code with attribution. It requires compliance with the license terms found in the official repository.
Common variations
You can also use the OpenAI-compatible openai SDK by specifying the base_url for Mistral's API. This is useful if you want to unify your AI calls under one SDK.
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["MISTRAL_API_KEY"], base_url="https://api.mistral.ai/v1")
response = client.chat.completions.create(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Explain the Mistral open source license."}]
)
print(response.choices[0].message.content) output
The Mistral open source license permits free use and modification with attribution. Refer to the official license file for full terms.
Troubleshooting
- If you get authentication errors, verify that MISTRAL_API_KEY is correctly set in your environment.
- For network errors, check your internet connection and firewall settings.
- If the model name is invalid, confirm you are using a current model like mistral-large-latest.
Key Takeaways
- The Mistral open source license is permissive and requires attribution.
- Use the official mistralai SDK or OpenAI-compatible SDK with your API key.
- Always check the official Mistral GitHub for the latest license terms.