Mistral
Access 19 Mistral models through Mastra’s model router. Authentication is handled automatically using the MISTRAL_API_KEY
environment variable.
Learn more in the Mistral documentation .
MISTRAL_API_KEY=your-api-key
import { Agent } from "@mastra/core";
const agent = new Agent({
name: "my-agent",
instructions: "You are a helpful assistant",
model: "mistral/codestral-latest"
});
// Generate a response
const response = await agent.generate("Hello!");
// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}
Mastra uses the OpenAI-compatible /chat/completions
endpoint. Some provider-specific features may not be available. Check the Mistral documentation for details.
Models
Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
---|---|---|---|---|---|---|---|---|
mistral/devstral-medium-2507 | 128K | $0.40 | $2 | |||||
mistral/open-mixtral-8x22b | 64K | $2 | $6 | |||||
mistral/ministral-8b-latest | 128K | $0.10 | $0.10 | |||||
mistral/pixtral-large-latest | 128K | $2 | $6 | |||||
mistral/ministral-3b-latest | 128K | $0.04 | $0.04 | |||||
mistral/pixtral-12b | 128K | $0.15 | $0.15 | |||||
mistral/mistral-medium-2505 | 131K | $0.40 | $2 | |||||
mistral/devstral-small-2505 | 128K | $0.10 | $0.30 | |||||
mistral/mistral-medium-2508 | 262K | $0.40 | $2 | |||||
mistral/mistral-small-latest | 128K | $0.10 | $0.30 | |||||
mistral/magistral-small | 128K | $0.50 | $2 | |||||
mistral/devstral-small-2507 | 128K | $0.10 | $0.30 | |||||
mistral/codestral-latest | 256K | $0.30 | $0.90 | |||||
mistral/open-mixtral-8x7b | 32K | $0.70 | $0.70 | |||||
mistral/mistral-nemo | 128K | $0.15 | $0.15 | |||||
mistral/open-mistral-7b | 8K | $0.25 | $0.25 | |||||
mistral/mistral-large-latest | 131K | $2 | $6 | |||||
mistral/mistral-medium-latest | 128K | $0.40 | $2 | |||||
mistral/magistral-medium-latest | 128K | $2 | $5 |
Advanced Configuration
Custom Headers
const agent = new Agent({
name: "custom-agent",
model: {
url: "https://api.mistral.ai/v1/chat/completions",
modelId: "codestral-latest",
apiKey: process.env.MISTRAL_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});
Dynamic Model Selection
const agent = new Agent({
name: "dynamic-agent",
model: ({ runtimeContext }) => {
const useAdvanced = runtimeContext.task === "complex";
return useAdvanced
? "mistral/codestral-latest"
: "mistral/devstral-medium-2507";
}
});
Direct Provider Installation
This provider can also be installed directly as a standalone package, which can be used instead of the Mastra model router string. View the package documentation for more details.
npm install @ai-sdk/mistral