Table of Contents
Module 1: Getting Started with Mistral
This module introduces Mistral as an AI provider: its history, the large language models (LLMs) it offers, the licenses attached to those models, the technical characteristics that set it apart, and the use cases it is best suited for.
History of Mistral
Mistral is a comparatively young company, so its history is short but eventful.
- April 2023 – Mistral was founded in Paris, France (some sources mention February or May 2023, but the company’s official position is April 2023).
- The three co-founders attended the same university and had previously worked at Meta and at Google’s AI subsidiary, DeepMind, before starting their own company.
- The name “Mistral” refers to a strong wind typical of certain regions of France, and is pronounced using the French pronunciation.
- Mistral secured funding early, even before publicly releasing any product.
- September 2023 – Mistral released its first LLM, Mistral 7B. It attracted significant attention for being powerful yet efficient, a combination that was still relatively rare in an AI industry often characterized as an “arms race” fueled by enormous amounts of capital.
- End of 2023 – Mistral announced it had raised $2 billion USD in funding, making it one of the first European AI “unicorns” (a unicorn being a company valued at $1 billion USD or more).
- February 2024 – Microsoft became an investor in Mistral.
- Mid-2024 – As part of the relationship with Microsoft, Azure gained first-class support for Mistral models, allowing them to run on Microsoft’s cloud.
- November 2024 – Mistral’s chatbot, Le Chat (meaning both “the chatbot” and “the cat” in French — comparable to offerings like ChatGPT), received a major update.
With solid financial backing and continued growth, Mistral keeps releasing new models and features at a rapid pace.
timeline
title History of Mistral
April 2023 : Company founded in Paris, France
September 2023 : Mistral 7B released, first LLM
End of 2023 : $2 billion USD raised, European AI unicorn status
February 2024 : Microsoft becomes an investor
Mid-2024 : Azure adds first-class support for Mistral models
November 2024 : Major update to Le Chat chatbot
Mistral Models
Mistral has released dozens of models. Many are niche variants for specific use cases, or updated versions of existing models, so an always-up-to-date list is impractical. The major model families are described below.
Mistral 7B kicked off the “Mistral craze.” A large language model has many parameters (also called weights or biases) that act as settings fine-tuning the model’s capabilities. The “7B” refers to the number of parameters — 7 billion (technically 7.3 billion). Generally speaking, more parameters can mean better results, but also higher cost to run.
Mixtral currently comes in two variants: 8X7B and 8X22B (the 8X22B model technically uses 39 billion parameters). Mixtral uses a different architecture called sparse mixture of experts — the “x” in the name reflects this. This approach splits the model into different components, each specialized like an “expert” in a particular kind of task.
Both Mistral 7B and Mixtral 8X7B are now considered legacy models — they are no longer actively refined. Instead, Mistral offers newer models, some brand new, some version updates of existing ones. Mistral also differentiates several models by size — small, medium, and large — which refers to the model’s parameter count and capability: smaller models are cheaper to run, larger models tend to produce better results (at least in most cases). The right choice depends on cost and quality requirements.
Several Mistral models serve specific purposes:
- Codestral – specialized for code generation. Other Mistral models can also help with code, but Codestral was trained specifically for that task.
- Mathstral – specialized for math and STEM (science, technology, engineering, mathematics) use cases.
- Pixtral – specialized for images. It can understand image content, works well with documents, and can even generate simple images.
- Ministral – a genuinely small model, small enough to run on virtually any device, well-suited for edge computing. Unlike most LLMs, which run in the cloud where compute resources are plentiful and scalable, Ministral can run locally, meaning data sent to the model never has to leave the device. Ministral Tiny is smaller still.
- Magistral – named after the French word for “masterful.” It is a reasoning model: one that not only tries to solve a problem but also exposes the chain of thought behind its answer, which can increase user trust in the result.
mindmap
root((Mistral Model Family))
Legacy
Mistral 7B
Mixtral 8X7B
Mixtral 8X22B
General Purpose
Mistral Small
Mistral Medium
Mistral Large
Specialized
Codestral - code generation
Mathstral - math and STEM
Pixtral - images and documents
Edge / Local
Ministral
Ministral Tiny
Reasoning
Magistral
Magistral Medium
| Model | Approximate Size | Category | Primary Purpose |
|---|---|---|---|
| Mistral 7B | 7.3B parameters | Legacy | General-purpose LLM, the original model |
| Mixtral 8X7B | 8 experts × 7B | Legacy | Sparse mixture-of-experts general LLM |
| Mixtral 8X22B | 8 experts × ~39B | Legacy | Larger sparse mixture-of-experts LLM |
| Mistral Small / Medium / Large | Varies | General purpose | Tiered cost vs. quality general LLMs |
| Codestral | Varies | Specialized | Code generation and completion |
| Mathstral | Varies | Specialized | Math and STEM reasoning |
| Pixtral | 12B+ variants | Specialized (multimodal) | Image understanding, documents, simple image generation |
| Ministral / Ministral Tiny | Small | Edge / local | On-device and edge computing, data stays local |
| Magistral / Magistral Medium | Varies | Reasoning | Chain-of-thought reasoning model |
| Devstral (Small / Medium) | Varies | Specialized | Agentic coding model |
Mistral Licenses
Different Mistral models come with different licenses. Mistral’s licensing terms can change with little notice, so it is important to always check the current, official Mistral website to confirm the license attached to a given model at any point in time. There are three main licenses Mistral uses, typically applying to the model weights (the parameters that determine model behavior):
- Apache 2.0 – created by the Apache Software Foundation. This is a very permissive open-source license: a model can be used in essentially any way, as long as the license terms are respected. The main restriction is that published modifications must also be released under Apache 2.0 — you cannot repackage the model under a commercial license.
- Proprietary license – used for some Mistral models, particularly paid ones, where Mistral retains more rights than under an open-source license.
- Mistral Research License (sometimes called the “Mistral AI Research License”) – intended for research purposes.
A related, more specific license introduced with the Codestral model release (May 2024) is the Mistral AI Non-Production License (MNPL). It permits use of a model for non-commercial and research purposes. While not fully compatible with Apache 2.0, it shares a similar spirit.
Examples of how these licenses apply to specific models:
- Legacy 7B, Mixtral models, and Mistral Small publish their weights under Apache 2.0 — free to use within the license terms.
- Mistral Medium and Magistral Medium — Mistral’s flagship models — do not publish their weights, so they are proprietary. Several newer models released for commercial purposes follow the same pattern.
- For some large editions, weights are available under the Mistral AI Research License, with the expectation that research and experimentation results are contributed back to the project.
- Pixtral 12B provides weights under Apache 2.0; other Pixtral models use the research license.
- Devstral Small releases weights under Apache 2.0; Devstral Medium does not.
flowchart TD
A[Mistral Model License] --> B{License Type}
B --> C[Apache 2.0<br/>Open Source]
B --> D[Proprietary]
B --> E[Mistral AI Research License]
B --> F[Mistral AI Non-Production License - MNPL]
C --> C1[Mistral 7B legacy]
C --> C2[Mixtral 8X7B / 8X22B legacy]
C --> C3[Mistral Small]
C --> C4[Pixtral 12B]
C --> C5[Devstral Small]
D --> D1[Mistral Medium]
D --> D2[Magistral Medium]
D --> D3[Devstral Medium]
E --> E1[Some large model editions]
E --> E2[Other Pixtral models]
F --> F1[Codestral - non-commercial use]
| License | Nature | Example Models | Key Restriction |
|---|---|---|---|
| Apache 2.0 | Permissive open source | Mistral 7B, Mixtral 8X7B/8X22B, Mistral Small, Pixtral 12B, Devstral Small | Modifications must also be released under Apache 2.0 |
| Proprietary | Closed / commercial | Mistral Medium, Magistral Medium, Devstral Medium | Mistral retains full rights; usage governed by commercial terms |
| Mistral AI Research License | Research-oriented | Some large model editions, other Pixtral models | Intended for research; hope that results are contributed back |
| Mistral AI Non-Production License (MNPL) | Non-commercial use | Codestral | Non-commercial and research use only |
The overall message: for most use cases there is an open-source version of a Mistral model available, but if more advanced features or performance are required, a proprietary option typically exists as well.
What Makes Mistral Unique
Several characteristics help distinguish Mistral from other AI providers, keeping in mind that in a fast-moving field, today’s leader can quickly be overtaken:
- Open source availability – Many of Mistral’s models are open source, which is not a given in the industry; many providers treat model weights as trade secrets. Mistral’s open licenses make it easy and inexpensive to experiment and build value through applications, and many of these models can be run locally.
- Broad cloud availability – Even without local hardware, major cloud providers already support Mistral models: Microsoft Azure, AWS (Amazon), and Google Cloud. Cloud infrastructure is typically more powerful for running large models than average local hardware.
- GDPR compliance – As a European company, Mistral adheres to the EU-wide General Data Protection Regulation (GDPR). Compliance with GDPR is mandatory when working with customers based in Europe, and while other providers may also comply, differing regional interpretations of data protection make Mistral’s native EU compliance a convenient advantage for European markets.
- High performance – Every provider claims strong performance, but Mistral consistently performs well in independent and self-reported benchmarks compared to competitors.
mindmap
root((What Makes Mistral Unique))
Open Source Models
Many Apache 2.0 licensed models
Can be run locally
Cheap to experiment with
Cloud Availability
Microsoft Azure
AWS - Amazon Bedrock
Google Cloud - Vertex AI
GDPR Compliance
European company
EU-wide data protection
High Performance
Strong benchmark results
Good cost-to-performance ratio
Comparing Mistral to the Competition
Mistral’s original 7B model — while now legacy — was often faster than models like Llama that use more parameters, and faster results generally translate into lower operating costs. Mistral’s performance-to-cost ratio is widely considered excellent: results are strong while the cost required to reach comparable quality is often lower than with some competing providers.
- Devstral, an agentic LLM for writing code, performs very well against other coding-focused models (results can vary depending on the programming language and framework being used).
- Codestral, the model typically used for AI-assisted coding (“co-pilot”-style scenarios), also performs strongly in benchmarks.
This does not mean Mistral has been, is, or always will be the best-performing provider — the field changes quickly — but its track record so far has been consistently strong.
Mistral’s Core Technical Features
Mistral uses several cutting-edge architectural techniques. While a full technical treatment is outside the scope of an introductory course, three aspects stand out:
-
Sliding window attention Self-attention is a core mechanism in many AI models: it describes how a model gives more weight to important parts of the input than unimportant ones, allowing it to access the whole input (or parts of it) while processing it piece by piece, and thereby preserving context. Self-attention lets the model weigh the importance of input tokens to optimize output quality. Sliding window attention still uses self-attention, but restricts it to nearby tokens only. The model therefore does not necessarily have knowledge of the full context, but the approach is far more efficient — requiring much less memory and processing time, usually without a significant negative effect on output quality.
-
Group Query Attention (GQA) GQA is a mechanism that splits a query into groups and runs the attention mechanism within those groups. This strikes a balance between low memory use, high speed, and high output quality. GQA can reduce computational complexity and may even improve results, since attention is computed within smaller groups, and the approach scales well: larger data volumes simply translate into more groups.
-
Mixture of Experts (MoE) A problem is split into parts, and different specialized sub-models (“experts”) work on specific aspects of the input — analogous to having dedicated HTML, CSS, and JavaScript specialists build a website instead of relying solely on full-stack developers. This approach is efficient because the entire model is not required for every task; each part of a problem is instead routed to the most appropriate expert.
flowchart LR
subgraph Full Self-Attention
A1[Token 1] --- A2[Token 2] --- A3[Token 3] --- A4[Token 4] --- A5[Token 5]
A1 --- A3
A1 --- A4
A1 --- A5
A2 --- A4
A2 --- A5
end
flowchart LR
subgraph Sliding Window Attention
B1[Token 1] --- B2[Token 2]
B2 --- B3[Token 3]
B3 --- B4[Token 4]
B4 --- B5[Token 5]
end
flowchart TD
Q[Incoming Query] --> G1[Query Group 1]
Q --> G2[Query Group 2]
Q --> G3[Query Group 3]
G1 --> R1[Attention within Group 1]
G2 --> R2[Attention within Group 2]
G3 --> R3[Attention within Group 3]
R1 --> OUT[Combined Output]
R2 --> OUT
R3 --> OUT
flowchart TD
Input[Input Problem] --> Router[Routing / Gating Mechanism]
Router --> E1[Expert 1: e.g. HTML-like specialization]
Router --> E2[Expert 2: e.g. CSS-like specialization]
Router --> E3[Expert 3: e.g. JavaScript-like specialization]
E1 --> Combine[Combined Output]
E2 --> Combine
E3 --> Combine
| Technique | Goal | Trade-off / Benefit |
|---|---|---|
| Sliding Window Attention | Limit self-attention to nearby tokens | Much lower memory/processing cost; less full-context awareness |
| Group Query Attention (GQA) | Split queries into groups for attention | Balances memory, speed, and quality; scales well with data volume |
| Mixture of Experts (MoE) | Route sub-problems to specialized “expert” sub-models | Efficient — only relevant experts are engaged per task |
Mistral Use Cases
Given the variety of Mistral models available (open source and proprietary), Mistral supports several common use case categories:
- Natural Language Processing (NLP) / Conversational AI – Understanding written text (e.g., parsing a question) and generating text (e.g., producing an answer). This extends into full conversations with follow-up questions and additional context, commonly seen in chatbots (e.g., Mistral’s own Le Chat) and virtual assistants that augment or replace customer service functions.
- Coding support – Writing code from scratch, extending existing code with new functionality, debugging and fixing issues, and writing unit tests. Mistral models are increasingly used for the latter, since many developers are reluctant to write their own tests while AI models are not.
- Agentic AI – Rather than directly instructing an AI on what to do, agents are used: programs that perform work and make decisions along the way. This raises trust questions (e.g., would you trust an agent to make a purchase on your behalf without supervision?), but also enables fully autonomous systems.
mindmap
root((Mistral Use Cases))
NLP / Conversational AI
Chatbots - e.g. Le Chat
Virtual assistants
Customer service augmentation
Coding Support
Writing new code
Extending existing code
Debugging and fixing issues
Writing unit tests
Agentic AI
Autonomous decision-making
Task execution on user's behalf
Module 2: Developing with Mistral
This module covers the practical side of working with Mistral: how and where to run Mistral models — locally and in the cloud — and how to build applications against Mistral using its official and third-party SDKs.
Running Mistral Locally
Several of Mistral’s models are optimized to run on a local machine, at least as an option, provided the hardware is capable enough. Three popular local tooling options are covered below.
flowchart TD
Start[I want to run Mistral] --> Q{Where?}
Q -->|Locally| L{Which local tool?}
Q -->|Cloud| C{Which cloud provider?}
L --> Ollama[Ollama]
L --> LlamaCpp[Llama.cpp]
L --> LMStudio[LM Studio]
C --> Azure[Microsoft Azure - Azure AI Foundry]
C --> AWS[AWS - Amazon Bedrock]
C --> GCP[Google Cloud - Vertex AI]
C --> MistralCompute[Mistral Compute]
Mistral with Ollama
Ollama (available from ollama.com) is one of the most popular tools for interacting with LLMs, including in the cloud, but with a specialty in running models locally. It is available for the three main platforms: macOS, Linux, and Windows. Ollama supports a large number of models, including several from Mistral, and models can be used directly from the CLI or through other means.
After installing Ollama, the system gains access to a simple UI as well as the ollama command-line tool, which offers a number of subcommands. For example, Ollama can start a server that exposes an HTTP endpoint, allowing software to interact with the model through an API. Alternatively, a model can be run directly from the CLI:
ollama run mistral
The first time a model is run, it is pulled and downloaded from a registry. Once downloaded, a text chat-like interface becomes available for interacting with the model directly.
Example interaction:
> What's 6 x 7?
42
This runs entirely locally, as opposed to in the cloud, giving full control over the environment.
Mistral with Llama.cpp
Llama.cpp is another option for running Mistral (and other) models locally. Despite the .cpp in its name — referencing the fact that the implementation is written in C — Llama.cpp can be used with any language or tool; the name simply reflects the implementation language.
Llama.cpp can be installed through a variety of options, including package managers such as Homebrew (popular on macOS), or via frequent binary releases published for a variety of operating systems.
There are multiple ways to run Llama.cpp:
- Launch a server and communicate with it through an API — well-suited for use from your own code.
- Use the CLI directly for interactive chat-like sessions.
A typical workflow retrieves a Mistral model from Hugging Face, installs it locally (which can take a while), and then allows interactive chat through the CLI.
Example interaction:
> Write a JavaScript function that checks whether an input is a number.
// Implementation 1
function isNumber(value) {
return typeof value === 'number' && !Number.isNaN(value);
}
// Implementation 2
function isNumber(value) {
return !isNaN(parseFloat(value)) && isFinite(value);
}
Along with the code, Llama.cpp’s chat interface also returns an explanation of why each implementation works the way it does.
Mistral with LM Studio
LM Studio is a desktop GUI application for managing and using LLMs locally, offering many features beyond what a simple CLI provides. Getting started involves the following steps:
- Pick a model to use. LM Studio installs a default model, but Mistral models are also available — for example, under “staff picks,” the original Mistral 7B model (even though it has been discontinued, it remains available).
- Review the model’s information and license.
- Download the model into the application.
- Load the model once the download completes.
- Interact with the model — options include an SDK, but the simplest way to get started is through the built-in chat interface. Depending on the model, messages can include attached files and images.
Example interaction:
> What is the meaning of life?
[The model responds with a philosophical answer rather than a numeric one.]
This demonstrates working with a Mistral model directly on local, even average, hardware.
| Tool | Interface | Distribution | Typical Use |
|---|---|---|---|
| Ollama | CLI + simple UI + HTTP server/API | ollama.com, package managers | Quick local model management and chat, API for integration |
| Llama.cpp | CLI + server/API | Package managers (e.g., Homebrew), frequent binary releases | Lightweight local inference in C-based runtime, usable from any language via API |
| LM Studio | Desktop GUI | Desktop application download | Visual model discovery/download/chat, beginner-friendly local experimentation |
Running Mistral in the Cloud
The better the hardware, the better the performance of AI applications and interactions with models. Cloud hardware is typically more powerful and more scalable than local hardware. All major cloud providers offer hosted Mistral models, with different names and programming models, but all support a range of Mistral offerings:
- Microsoft Azure – Mistral models are available through Azure AI Foundry.
- AWS (Amazon) – Mistral models are available through Amazon Bedrock.
- Google Cloud – Mistral models are available through Vertex AI.
- Mistral Compute – Mistral also runs its own cloud offering, named Mistral Compute, which may be of particular interest from a GDPR perspective since computation takes place in Mistral’s own cloud infrastructure rather than locally.
Cloud provider UIs change frequently, so rather than detailing every provider’s exact workflow, a single representative example — Azure AI Foundry — illustrates the general pattern:
- In Azure AI Foundry, create an AI application (frequently an agent).
- Choose the model for your use case, including a full catalog of Mistral models.
- Review model details, including whether a specific model has been retired.
- Use the model — this may require a subscription, or usage may already be included as part of an existing subscription.
- Optionally fine-tune supported models (not every model supports fine-tuning).
- Once running, leverage the model from your own cloud-based applications.
sequenceDiagram
participant Dev as Developer
participant Foundry as Azure AI Foundry
participant Model as Mistral Model
Dev->>Foundry: Create AI application / agent
Dev->>Foundry: Select Mistral model from catalog
Foundry-->>Dev: Model details (license, retirement status)
Dev->>Foundry: Configure subscription / fine-tuning (optional)
Dev->>Model: Send request via cloud application
Model-->>Dev: Response
| Cloud Provider | Mistral Access Point | Notes |
|---|---|---|
| Microsoft Azure | Azure AI Foundry | First-class Mistral support since mid-2024 (Microsoft investment) |
| AWS (Amazon) | Amazon Bedrock | Access to a catalog of Mistral models |
| Google Cloud | Vertex AI | Access to a catalog of Mistral models |
| Mistral Compute | Mistral’s own cloud | Mistral-operated infrastructure, notable for GDPR-sensitive workloads |
Developing Applications with the Mistral SDKs
Mistral provides official SDKs for a couple of languages, and the wider community maintains solid unofficial/third-party SDKs for many other technologies. The documentation at docs.mistral.ai, under “SDK Clients,” lists both official and third-party options.
flowchart TD
Root[Mistral SDK Clients] --> Official[Official SDKs]
Root --> ThirdParty[Third-Party SDKs]
Official --> Py[Python - mistralai]
Official --> TS[TypeScript - @mistralai/mistralai]
ThirdParty --> DotNet[.NET - e.g. Mistral.SDK on NuGet]
ThirdParty --> Others[Other languages/frameworks]
Getting an API Key
Before using any SDK, an API key is required:
- Sign up at
mistral.ai. - Create a subscription — a free, experimental tier is available (with limitations), alongside a paid option.
- On
console.mistral.ai, navigate to API keys and create a new key (e.g., name itmy-mistral-key). - Optionally set an expiration date for the key.
- Copy and store the generated key securely — it is only shown once, and it is tied to your individual account.
The generated key is typically supplied to applications through an environment variable (referred to as API_KEY in the examples below).
Python: Code Completion with Codestral
Python has an official Mistral SDK, distributed as the mistralai package via pip. The following example (based on a fictitious “Globoticket” event ticketing scenario) uses Mistral to complete a function that converts a temperature from Fahrenheit to Celsius, using Fill-in-the-Middle (FIM) style completion: a prefix (prompt) defines the start of the function, and a suffix defines code that comes after it, with Mistral filling in the middle.
pip install mistralai
import os
from mistralai import Mistral
api_key = os.environ["API_KEY"]
client = Mistral(api_key=api_key)
model = "codestral-latest"
prompt = "def convertFahrenheitToCelsius(tempF: int):"
suffix = "tempF = int(input('Enter a temperature in Fahrenheit: '))\nprint(convertFahrenheitToCelsius(tempF))"
response = client.fim.complete(
model=model,
prompt=prompt,
suffix=suffix,
temperature=0,
)
print(response)
Running this script sends the prompt (the function signature) and suffix (the calling code) to Codestral through the API key, and Mistral returns a completed implementation of the function body, filling in the classic conversion formula:
$$ C = (F - 32) \times \frac{5}{9} $$
Expected output (implementation returned by Codestral):
def convertFahrenheitToCelsius(tempF: int):
return (tempF - 32) * 5 / 9
This is an example of code completion — specifically, filling in code in the middle of an existing structure — but Mistral can equally be used to simply continue and finish code starting from a given prefix.
TypeScript: Image Generation with Agents
TypeScript is the second language with an official Mistral SDK, distributed as an NPM package (@mistralai/mistralai). The following example, again based on the “Globoticket” scenario, generates an image of an analog clock showing an event’s start time, using Mistral’s agent and image generation tool features.
npm install @mistralai/mistralai
package.json for the demo:
{
"dependencies": {
"@mistralai/mistralai": "^1.10.0"
},
"devDependencies": {
"@types/node": "^24.10.0",
"typescript": "^5.9.3"
}
}
drawClock.ts:
import { Mistral } from '@mistralai/mistralai';
const apiKey = process.env.API_KEY;
const client = new Mistral({apiKey: apiKey});
async function run() {
let imageAgent = await client.beta.agents.create({
model: "mistral-medium-latest",
name: "Image Generation Agent",
description: "Agent to generate images",
tools: [{
type: "image_generation"
}],
completionArgs:{
temperature: 0.3,
topP: 0.95,
}
});
let conversation = await client.beta.conversations.start({
agentId: imageAgent.id,
inputs: "Draw an analog clock showing it's 7:30 p.m.",
store:false,
});
console.log(conversation.outputs);
}
run();
Run the script with a TypeScript runner such as tsx:
npx tsx drawClock.ts
The workflow:
- Import the Mistral SDK and create a client using the API key from an environment variable.
- Create an agent, since image generation is a tool used via agents. Agents can also be created through the Mistral web UI (Mistral AI Studio) instead of in code — the API surface for this may evolve over time (currently exposed under the
betanamespace). - Configure the agent’s allowed tools to include
image_generation. - Start a conversation with the agent, referencing its ID, and supply the input prompt (e.g., “Draw an analog clock showing it’s 7:30 p.m.”).
sequenceDiagram
participant App as TypeScript App
participant SDK as Mistral SDK
participant Agent as Image Generation Agent
participant API as Mistral API
App->>SDK: new Mistral({apiKey})
App->>SDK: client.beta.agents.create(...)
SDK->>API: Create agent with image_generation tool
API-->>SDK: agent.id
App->>SDK: client.beta.conversations.start({agentId, inputs})
SDK->>API: Send conversation input
API->>Agent: Route to image generation tool
Agent-->>API: Generated image content
API-->>App: conversation.outputs (tool execution + generated image)
Two aspects of the returned output are worth noting:
tool.executioncontains the actual, more elaborate prompt used internally by the agent (e.g., additional detail such as “the hour hand should be halfway between 7 and 8”).message.outputcontains the generated image, embedded within acontentproperty; converting that content into a viewable image file requires some additional handling, and is not covered in depth here.
The same agent can also be inspected and used interactively through Mistral AI Studio (part of the Mistral web UI), where the created “Image Generation Agent” appears and can be prompted directly (e.g., “draw an analog clock showing it’s 7:30 PM”), producing a similarly elaborate internal prompt and a generated (and occasionally imperfect) clock image.
.NET: Building a Simple Chatbot
.NET is not listed among Mistral’s official SDKs, but active, well-maintained third-party SDKs exist. Searching NuGet.org for “Mistral” surfaces several packages; Mistral.SDK has been available for a long time, remains maintained, and its project site is essentially its GitHub repository.
Project file (Globoticket.Mistral.csproj):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mistral.SDK" Version="2.3.1" />
</ItemGroup>
</Project>
Program.cs — a simple console chatbot prototype for the “Globoticket” scenario:
using Mistral.SDK;
using Mistral.SDK.DTOs;
var client = new MistralClient();
var prompt = string.Empty;
do
{
Console.Write("> ");
prompt = Console.ReadLine() ?? string.Empty;
var request = new ChatCompletionRequest(
ModelDefinitions.OpenMistral7b,
new List<ChatMessage>()
{
new ChatMessage(ChatMessage.RoleEnum.User, prompt)
});
var response = await client.Completions.GetCompletionAsync(request);
Console.WriteLine(response.Choices.First().Message.Content);
} while (!string.IsNullOrWhiteSpace(prompt) && prompt.Trim() != "bye");
Key points about this implementation:
- The
MistralClientconstructor requires no explicit API key argument by default — it reads the key from an environment variable. An API key can alternatively be supplied explicitly as a constructor argument. - The program loops, prompting the user for input, sending it to a Mistral model (
OpenMistral7bin this example, though any available model can be substituted), and printing the response. - The loop ends when the user enters
byeor an empty prompt.
Example interaction:
> what is 1 + 2
That equals 3.
> what is 0.1 + 0.2
0.3
Switching the model to a larger one (e.g., Mistral Medium) can surface a more detailed explanation for tricky cases like floating-point addition (0.1 + 0.2 famously does not equal exactly 0.3 in binary floating-point arithmetic — try it in a JavaScript console).
Security note: This chatbot prototype includes no security features whatsoever — any prompt from any user is passed directly to the model. AI security is an important topic in its own right, beyond the scope of an introductory course, but as a general principle: never accept user input verbatim without validation. Always define boundaries around the kinds of queries, prompts, and inputs your application allows, and consider adding safeguards before forwarding user input to an AI model.
sequenceDiagram
participant User
participant App as .NET Console App
participant Client as MistralClient
participant API as Mistral API
loop Until "bye" or empty input
User->>App: Enter prompt
App->>Client: GetCompletionAsync(ChatCompletionRequest)
Client->>API: Send chat completion request
API-->>Client: Response
Client-->>App: Choices[0].Message.Content
App-->>User: Print response
end
| Language | SDK Type | Package | Client Constructor Behavior |
|---|---|---|---|
| Python | Official | mistralai (pip) | Requires explicit api_key argument |
| TypeScript | Official | @mistralai/mistralai (npm) | Requires explicit apiKey argument |
| .NET | Third-party | Mistral.SDK (NuGet) | Defaults to reading API key from environment variable; explicit key optional |
Summary
Mistral is a European AI provider, founded in Paris in April 2023, that has quickly grown into a major player in the LLM space, backed by significant funding (including investment from Microsoft) and a broad, fast-evolving catalog of models.
Key principles covered in this course:
- Model variety – Mistral offers general-purpose models in small/medium/large tiers, legacy models (Mistral 7B, Mixtral), and specialized models for code (Codestral), math/STEM (Mathstral), images/documents (Pixtral), edge/local use (Ministral), and reasoning with chain-of-thought (Magistral).
- Licensing flexibility – Many models are available under the permissive Apache 2.0 license, while flagship and commercial models are proprietary; specialized licenses like the Mistral AI Research License and the Mistral AI Non-Production License (MNPL) cover research and non-commercial scenarios.
- Differentiators – Open-source availability, broad multi-cloud support, native GDPR compliance as a European company, and a strong price-to-performance track record.
- Underlying technology – Efficiency- and quality-oriented techniques such as sliding window attention, group query attention (GQA), and mixture of experts (MoE) architectures.
- Deployment flexibility – Models can run locally via Ollama, Llama.cpp, or LM Studio, or in the cloud via Azure AI Foundry, Amazon Bedrock, Google Cloud Vertex AI, or Mistral’s own Mistral Compute offering.
- Developer tooling – Official SDKs exist for Python and TypeScript, with solid third-party SDKs (e.g., for .NET) covering additional languages, all built around a simple API-key-based authentication model.
Quick-Reference Table
| Area | Options / Examples |
|---|---|
| Legacy models | Mistral 7B, Mixtral 8X7B, Mixtral 8X22B |
| General-purpose tiers | Mistral Small, Mistral Medium, Mistral Large |
| Specialized models | Codestral (code), Mathstral (math/STEM), Pixtral (images), Ministral (edge), Magistral (reasoning) |
| Open-source license | Apache 2.0 |
| Restricted licenses | Proprietary, Mistral AI Research License, Mistral AI Non-Production License (MNPL) |
| Local tooling | Ollama, Llama.cpp, LM Studio |
| Cloud platforms | Azure AI Foundry, Amazon Bedrock, Google Cloud Vertex AI, Mistral Compute |
| Official SDKs | Python (mistralai), TypeScript (@mistralai/mistralai) |
| Third-party SDKs | .NET (Mistral.SDK), and others |
Getting Started Checklist
- Decide whether your use case favors an open-source (Apache 2.0) model or requires a proprietary/flagship model.
- Choose between running locally (Ollama, Llama.cpp, LM Studio) or in the cloud (Azure, AWS, Google Cloud, Mistral Compute), based on hardware, scalability, and data-residency (GDPR) requirements.
- Sign up at
mistral.aiand generate an API key viaconsole.mistral.ai. - Store the API key securely (e.g., as an environment variable), never hard-coded in source control.
- Select the SDK matching your stack (Python, TypeScript, or a third-party SDK such as .NET).
- Pick the right model for the task — e.g., Codestral for code generation, Pixtral for images, Magistral for reasoning-heavy tasks.
- Add appropriate input validation and safeguards before forwarding user-supplied input to any model in production applications.
Search Terms
mistral · llm · application · development · artificial · intelligence · generative · ai · developing · running