Mistral AI offers high-performance European models including Mistral Large, Pixtral for vision, and Codestral for code. This guide covers the API, function calling, and choosing the right Mistral model for your task.
Mistral offers a tiered lineup. Mistral Large is their most capable model, competitive with GPT-4o on reasoning and coding. Mistral Small is a fast, cost-effective model for classification and summarisation tasks. Codestral is a code-specialist model trained on 80+ programming languages and is one of the best code completion models available. Pixtral adds vision capabilities.
Mistral operates data centres in Europe, which makes it the preferred choice for EU companies with GDPR-sensitive data. Their API is also OpenAI-compatible, making migration from OpenAI a simple base URL change.
Create an account at console.mistral.ai. Generate an API key and store it as `MISTRAL_API_KEY`. Install the SDK: `pip install mistralai` (Python) or `npm install @mistralai/mistralai` (Node.js).
Make a call: `from mistralai import Mistral; client = Mistral(api_key=os.environ['MISTRAL_API_KEY']); response = client.chat.complete(model='mistral-small-latest', messages=[{'role': 'user', 'content': 'Hello!'}]); print(response.choices[0].message.content)`.
Mistral's API is fully OpenAI-compatible. Use the OpenAI SDK by changing the base URL: `client = OpenAI(base_url='https://api.mistral.ai/v1', api_key=os.environ['MISTRAL_API_KEY'])`. All existing OpenAI SDK code works without further changes — just change the model name to a Mistral model ID.
Mistral model IDs: `mistral-large-latest`, `mistral-small-latest`, `codestral-latest`, `pixtral-large-latest`. Pinned versions are available for production stability (e.g. `mistral-large-2407`).
Mistral Large and Small both support function calling with the same JSON Schema format as OpenAI. Mistral also supports the `response_format: {type: 'json_object'}` parameter for guaranteed JSON output, and structured output via `response_format: {type: 'json_schema', json_schema: {...}}` for schema-constrained responses.
For JSON extraction tasks, Mistral Small is a cost-effective choice — it reliably produces valid JSON at a fraction of Mistral Large's cost. Use Large only when the task requires complex reasoning or nuanced language understanding.
Codestral excels at fill-in-the-middle (FIM) completion — the paradigm used by IDE plugins where the model sees code before and after the cursor. Use the FIM endpoint: `client.fim.complete(model='codestral-latest', prompt='def fibonacci(n):\n ', suffix='\n return result')`. Codestral fills in the middle section.
For VS Code integration, use the Continue extension with Codestral as the tab autocomplete model. Configure it in `.continue/config.json` with `provider: 'mistral'` and `model: 'codestral-latest'`. This gives Copilot-quality completions for 80+ languages.
A practical introduction to the OpenAI API covering authentication, the chat completions endpoint, streaming, error handling, and cost management — with working code in Python and JavaScript.
Read guideThe Anthropic API gives access to the Claude model family. This guide covers authentication, the Messages API, vision inputs, tool use, and the key differences from the OpenAI API format.
Read guide