Mistral API Guide — Endpoints, Pricing, and Code Examples (2026)
Current flagship API: Large 4 public preview
For the new flagship use the documented model ID mistral-large-4, not an older model’s alias. See the Large 4 pricing and lifecycle reference: the API is usable now, while weights are announced for the end of October. Its 1M context and introductory rates are separate from the older-generation examples below. Confirm the current model documentation and account limits before migration; this update does not make the preview a stable production checkpoint.
📢 Update: Mistral Medium 3.5 is now available — 128B dense model replacing Medium 3.1 and Devstral 2. See the Medium 3.5 complete guide, how to run it locally, and API guide.
Mistral’s API (La Plateforme) gives you access to all their models through a single endpoint. Pricing starts at $0.10/1M tokens — 25-150x cheaper than Claude Opus. See our APIs & pricing hub for how it compares to other providers.
Quick start
pip install mistralai
from mistralai import Mistral
client = Mistral(api_key="your-mistral-key")
response = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Write a REST API in FastAPI"}]
)
print(response.choices[0].message.content)
Available models
| Model ID | Price (in/out per 1M) | Best for |
|---|---|---|
mistral-large-latest | $2 / $6 | Complex reasoning |
devstral-2-latest | $2 / $6 | Agentic coding |
codestral-latest | $0.30 / $0.90 | Code completion + FIM |
mistral-small-latest | $0.10 / $0.30 | Fast, cheap tasks |
Fill-in-the-Middle (Codestral)
Codestral’s killer feature — understands code before AND after the cursor:
response = client.fim.complete(
model="codestral-latest",
prompt="def fibonacci(n):\n ",
suffix="\n return result"
)
Via OpenRouter
from openai import OpenAI
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key="your-key")
response = client.chat.completions.create(
model="mistralai/mistral-large-2",
messages=[{"role": "user", "content": "Explain WebSockets"}]
)
See our OpenRouter guide.
JavaScript/TypeScript
import Mistral from '@mistralai/mistralai';
const client = new Mistral({ apiKey: 'your-key' });
const response = await client.chat.complete({
model: 'devstral-2-latest',
messages: [{ role: 'user', content: 'Refactor this to use async/await' }]
});
With coding tools
# Aider
aider --model mistralai/devstral-2 --api-key $MISTRAL_API_KEY
# Vibe CLI (native Mistral tool)
npm install -g @mistralai/vibe-cli
vibe
GDPR advantage
Mistral’s API runs on EU infrastructure. For European companies needing GDPR compliance, this means data stays in Europe without additional configuration. No Standard Contractual Clauses needed.
FAQ
Is the Mistral API free?
No, but it’s very affordable. Pricing starts at $0.10/1M input tokens for Mistral Small, making it 25–150x cheaper than premium models like Claude Opus. There’s no free tier, but the low per-token cost means light usage costs pennies per month.
How do I get a Mistral API key?
Sign up at La Plateforme (console.mistral.ai), add a payment method, and generate an API key from the dashboard. The key works immediately — no waitlist or approval process required.
Which Mistral model should I use via API?
Use mistral-small-latest for fast, cheap tasks; codestral-latest for code completion with fill-in-the-middle support; and mistral-large-latest or devstral-2-latest for complex reasoning and agentic coding tasks.
Does Mistral support function calling?
Yes, Mistral models support function calling (tool use) through their API. You can define tools with JSON schemas and the model will generate structured function calls, making it suitable for building AI agents and automated workflows.
Related: What is Mistral AI? · Mistral AI Complete Model Guide · How to Run Mistral Models Locally · Best Free AI APIs 2026 · How To Use Qwen 3 6 Api