Are you sure you want to delete this access key?
sidebar_label | title | description | keywords |
---|---|---|---|
Mistral AI | Mistral AI Provider - Complete Guide to Models, Reasoning, and API Integration | Configure Mistral AI Magistral reasoning models with multimodal capabilities, function calling, and OpenAI-compatible APIs | [mistral ai magistral reasoning openai alternative llm evaluation function calling multimodal ai code generation mistral api] |
The Mistral AI API provides access to cutting-edge language models that deliver exceptional performance at competitive pricing. Mistral offers a compelling alternative to OpenAI and other providers, with specialized models for reasoning, code generation, and multimodal tasks.
Mistral is particularly valuable for:
:::tip Why Choose Mistral?
Mistral Medium 3 offers GPT-4 class performance at $0.40/$2.00 per million tokens (input/output), representing significant cost savings compared to OpenAI's $2.50/$10.00 pricing for similar capabilities.
:::
To use Mistral AI, you need to set the MISTRAL_API_KEY
environment variable, or specify the apiKey
in the provider configuration.
Example of setting the environment variable:
export MISTRAL_API_KEY=your_api_key_here
The Mistral provider supports extensive configuration options:
providers:
- id: mistral:mistral-large-latest
config:
# Model behavior
temperature: 0.7 # Creativity (0.0-2.0)
top_p: 0.95 # Nucleus sampling (0.0-1.0)
max_tokens: 4000 # Response length limit
# Advanced options
safe_prompt: true # Content filtering
random_seed: 42 # Deterministic outputs
frequency_penalty: 0.1 # Reduce repetition
presence_penalty: 0.1 # Encourage diversity
Force structured JSON output:
providers:
- id: mistral:mistral-large-latest
config:
response_format:
type: 'json_object'
temperature: 0.3 # Lower temp for consistent JSON
tests:
- vars:
prompt: "Extract name, age, and occupation from: 'John Smith, 35, engineer'. Return as JSON."
assert:
- type: is-json
- type: javascript
value: JSON.parse(output).name === "John Smith"
providers:
# Option 1: Environment variable (recommended)
- id: mistral:mistral-large-latest
# Option 2: Direct API key (not recommended for production)
- id: mistral:mistral-large-latest
config:
apiKey: 'your-api-key-here'
# Option 3: Custom environment variable
- id: mistral:mistral-large-latest
config:
apiKeyEnvar: 'CUSTOM_MISTRAL_KEY'
# Option 4: Custom endpoint
- id: mistral:mistral-large-latest
config:
apiHost: 'custom-proxy.example.com'
apiBaseUrl: 'https://custom-api.example.com/v1'
providers:
# Reasoning model with optimal settings
- id: mistral:magistral-medium-latest
config:
temperature: 0.7
top_p: 0.95
max_tokens: 40960 # Full context for reasoning
# Code generation with FIM support
- id: mistral:codestral-latest
config:
temperature: 0.2 # Low for consistent code
max_tokens: 8000
stop: ['```'] # Stop at code block end
# Multimodal configuration
- id: mistral:pixtral-12b
config:
temperature: 0.5
max_tokens: 2000
# Image processing options handled automatically
Variable | Description | Example |
---|---|---|
MISTRAL_API_KEY |
Your Mistral API key (required) | sk-1234... |
MISTRAL_API_HOST |
Custom hostname for proxy setup | api.example.com |
MISTRAL_API_BASE_URL |
Full base URL override | https://api.example.com/v1 |
You can specify which Mistral model to use in your configuration. The following models are available:
Model | Context | Input Price | Output Price | Best For |
---|---|---|---|---|
mistral-large-latest |
128k | $2.00/1M | $6.00/1M | Complex reasoning, enterprise tasks |
mistral-medium-latest |
128k | $0.40/1M | $2.00/1M | Balanced performance and cost |
codestral-latest |
256k | $0.30/1M | $0.90/1M | Code generation, 80+ languages |
magistral-medium-latest |
40k | $2.00/1M | $5.00/1M | Advanced reasoning, step-by-step thinking |
Model | Context | Input Price | Output Price | Best For |
---|---|---|---|---|
mistral-small-latest |
128k | $0.10/1M | $0.30/1M | General tasks, cost-effective |
magistral-small-latest |
40k | $0.50/1M | $1.50/1M | Reasoning on a budget |
open-mistral-nemo |
128k | $0.15/1M | $0.15/1M | Multilingual, research |
pixtral-12b |
128k | $0.15/1M | $0.15/1M | Vision + text, multimodal |
open-mistral-7b
, mistral-tiny
, mistral-tiny-2312
open-mistral-nemo
, open-mistral-nemo-2407
, mistral-tiny-2407
, mistral-tiny-latest
mistral-small-2402
mistral-medium-2312
, mistral-medium
mistral-large-2402
mistral-large-2407
codestral-2405
codestral-mamba-2407
, open-codestral-mamba
, codestral-mamba-latest
open-mixtral-8x7b
, mistral-small
, mistral-small-2312
open-mixtral-8x22b
, open-mixtral-8x22b-2404
mistral-embed
- $0.10/1M tokens - 8k contextHere's an example config that compares different Mistral models:
providers:
- mistral:mistral-medium-latest
- mistral:mistral-small-latest
- mistral:open-mistral-nemo
- mistral:magistral-medium-latest
- mistral:magistral-small-latest
Mistral's Magistral models are specialized reasoning models announced in June 2025. These models excel at multi-step logic, transparent reasoning, and complex problem-solving across multiple languages.
magistral-small-2506
): 24B parameter open-source version under Apache 2.0 licensemagistral-medium-2506
): More powerful enterprise version with enhanced reasoning capabilitiesFor reasoning tasks, consider using these parameters for optimal performance:
providers:
- id: mistral:magistral-medium-latest
config:
temperature: 0.7
top_p: 0.95
max_tokens: 40960 # Recommended for reasoning tasks
Mistral offers vision-capable models that can process both text and images:
Use pixtral-12b
for multimodal tasks:
providers:
- id: mistral:pixtral-12b
config:
temperature: 0.7
max_tokens: 1000
tests:
- vars:
prompt: 'What do you see in this image?'
image: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD...'
Mistral models support advanced function calling for building AI agents and tools:
providers:
- id: mistral:mistral-large-latest
config:
temperature: 0.1
tools:
- type: function
function:
name: get_weather
description: Get current weather for a location
parameters:
type: object
properties:
location:
type: string
description: City name
unit:
type: string
enum: ['celsius', 'fahrenheit']
required: ['location']
tests:
- vars:
prompt: "What's the weather like in Paris?"
assert:
- type: contains
value: 'get_weather'
Mistral's Codestral models excel at code generation across 80+ programming languages:
providers:
- id: mistral:codestral-latest
config:
temperature: 0.2
max_tokens: 2000
tests:
- vars:
prompt: |
<fim_prefix>def calculate_fibonacci(n):
if n <= 1:
return n
<fim_suffix>
# Test the function
print(calculate_fibonacci(10))
<fim_middle>
assert:
- type: contains
value: 'fibonacci'
tests:
- description: 'Python API endpoint'
vars:
prompt: 'Create a FastAPI endpoint that accepts a POST request with user data and saves it to a database'
assert:
- type: contains
value: '@app.post'
- type: contains
value: 'async def'
- description: 'React component'
vars:
prompt: 'Create a React component for a user profile card with name, email, and avatar'
assert:
- type: contains
value: 'export'
- type: contains
value: 'useState'
description: 'Compare reasoning capabilities across Mistral models'
providers:
- mistral:magistral-medium-latest
- mistral:magistral-small-latest
- mistral:mistral-large-latest
- mistral:mistral-small-latest
prompts:
- 'Solve this step by step: {{problem}}'
tests:
- vars:
problem: "A company has 100 employees. 60% work remotely, 25% work hybrid, and the rest work in office. If remote workers get a $200 stipend and hybrid workers get $100, what's the total monthly stipend cost?"
assert:
- type: llm-rubric
value: 'Shows clear mathematical reasoning and arrives at correct answer ($13,500)'
- type: cost
threshold: 0.10
description: 'AI-powered code review using Codestral'
providers:
- id: mistral:codestral-latest
config:
temperature: 0.3
max_tokens: 1500
prompts:
- |
Review this code for bugs, security issues, and improvements:
```{{language}}
{{code}}
```
Provide specific feedback on:
1. Potential bugs
2. Security vulnerabilities
3. Performance improvements
4. Code style and best practices
tests:
- vars:
language: 'python'
code: |
import subprocess
def run_command(user_input):
result = subprocess.run(user_input, shell=True, capture_output=True)
return result.stdout.decode()
assert:
- type: contains
value: 'security'
- type: llm-rubric
value: 'Identifies shell injection vulnerability and suggests safer alternatives'
description: 'Analyze documents with text and images'
providers:
- id: mistral:pixtral-12b
config:
temperature: 0.5
max_tokens: 2000
tests:
- vars:
prompt: |
Analyze this document image and:
1. Extract key information
2. Summarize main points
3. Identify any data or charts
image_url: 'https://example.com/financial-report.png'
assert:
- type: llm-rubric
value: 'Accurately extracts text and data from the document image'
- type: length
min: 200
# Required
export MISTRAL_API_KEY="your-api-key-here"
# Optional - for custom endpoints
export MISTRAL_API_BASE_URL="https://api.mistral.ai/v1"
export MISTRAL_API_HOST="api.mistral.ai"
:::warning Security Best Practices
:::
Use Case | Recommended Model | Why |
---|---|---|
Cost-sensitive apps | mistral-small-latest |
Best price/performance ratio |
Complex reasoning | magistral-medium-latest |
Step-by-step thinking |
Code generation | codestral-latest |
Specialized for programming |
Vision tasks | pixtral-12b |
Multimodal capabilities |
High-volume production | mistral-medium-latest |
Balanced cost and quality |
providers:
- id: mistral:magistral-medium-latest
config:
max_tokens: 8000 # Leave room for 32k input context
temperature: 0.7
# Monitor costs across models
defaultTest:
assert:
- type: cost
threshold: 0.05 # Alert if cost > $0.05 per test
providers:
- id: mistral:mistral-small-latest # Most cost-effective
config:
max_tokens: 500 # Limit output length
Error: 401 Unauthorized
Solution: Verify your API key is correctly set:
echo $MISTRAL_API_KEY
# Should output your key, not empty
Error: 429 Too Many Requests
Solutions:
# Reduce concurrent requests
providers:
- id: mistral:mistral-large-latest
config:
timeout: 30000 # Increase timeout
Error: Context length exceeded
Solutions:
providers:
- id: mistral:mistral-medium-latest # 128k context
config:
max_tokens: 4000 # Leave room for input
Error: Model not found
Solution: Check model names and use latest versions:
providers:
- mistral:mistral-large-latest # ✅ Use latest
# - mistral:mistral-large-2402 # ❌ Deprecated
Enable debug logging:
export DEBUG=promptfoo:*
Test with simple prompts first:
tests:
- vars:
prompt: 'Hello, world!'
Check token usage:
tests:
- assert:
- type: cost
threshold: 0.01
Ready-to-use examples are available in our GitHub repository:
Run any of these examples locally:
npx promptfoo@latest init --example mistral
Individual Examples:
# Try the basic comparison
npx promptfoo@latest eval -c https://raw.githubusercontent.com/promptfoo/promptfoo/main/examples/mistral/promptfooconfig.comparison.yaml
# Test mathematical reasoning with Magistral models
npx promptfoo@latest eval -c https://raw.githubusercontent.com/promptfoo/promptfoo/main/examples/mistral/promptfooconfig.aime2024.yaml
# Test reasoning capabilities
npx promptfoo@latest eval -c https://raw.githubusercontent.com/promptfoo/promptfoo/main/examples/mistral/promptfooconfig.reasoning.yaml
:::tip Contribute Examples
Found a great use case? Contribute your example to help the community!
:::
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?