πŸ€– AI Tools
Β· 2 min read
Last updated on

Mistral API Guide β€” Endpoints, Pricing, and Code Examples (2026)


πŸ“’ 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.

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 IDPrice (in/out per 1M)Best for
mistral-large-latest$2 / $6Complex reasoning
devstral-2-latest$2 / $6Agentic coding
codestral-latest$0.30 / $0.90Code completion + FIM
mistral-small-latest$0.10 / $0.30Fast, 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