Mistral

Mistral AI provides access to state-of-the-art language models including Mistral Large, Mistral Medium, and other advanced models. Braintrust integrates seamlessly with Mistral through direct API access, wrapper functions for automatic tracing, and proxy support.

Setup

To use Mistral models, configure your Mistral API key in Braintrust.

  1. Get a Mistral API key from Mistral AI Console
  2. Add the Mistral API key to your organization's AI providers
  3. Set the Mistral API key and your Braintrust API key as environment variables
.env
MISTRAL_API_KEY=<your-mistral-api-key>
BRAINTRUST_API_KEY=<your-braintrust-api-key>
 
# If you are self-hosting Braintrust, set the URL of your hosted dataplane
# BRAINTRUST_API_URL=<your-braintrust-api-url>

API keys are encrypted using 256-bit AES-GCM encryption and are not stored or logged by Braintrust.

Use Mistral with Braintrust AI proxy

The Braintrust AI Proxy allows you to access Mistral models through a unified OpenAI-compatible interface.

First, install the braintrust and openai packages.

pnpm add braintrust openai

Then, initialize the client and make a request to a Mistral model via the Braintrust AI Proxy.

mistral_proxy.ts
import { OpenAI } from "openai";
 
const client = new OpenAI({
  baseURL: "https://api.braintrust.dev/v1/proxy",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
 
const response = await client.chat.completions.create({
  model: "mistral-large-latest",
  messages: [{ role: "user", content: "Hello, world!" }],
});

Trace logs with Mistral

Trace your Mistral LLM calls for observability and monitoring.

When using the Braintrust AI Proxy, API calls are automatically logged to the specified project.

mistral_trace.ts
import { OpenAI } from "openai";
import { initLogger } from "braintrust";
 
initLogger({
  projectName: "My Project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
 
const client = new OpenAI({
  baseURL: "https://api.braintrust.dev/v1/proxy",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
 
// All API calls are automatically logged
const result = await client.chat.completions.create({
  model: "mistral-large-latest",
  messages: [{ role: "user", content: "What is machine learning?" }],
});

The Braintrust AI Proxy is not required to trace Mistral API calls. For more control, learn how to customize traces.

Evaluate with Mistral

Evaluations distill the non-deterministic outputs of Mistral models into an effective feedback loop that enables you to ship more reliable, higher quality products. Braintrust Eval is a simple function composed of a dataset of user inputs, a task, and a set of scorers. To learn more about evaluations, see the Experiments guide.

mistral_eval.ts
import { Eval } from "braintrust";
import { OpenAI } from "openai";
 
const client = new OpenAI({
  baseURL: "https://api.braintrust.dev/v1/proxy",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
 
Eval("Mistral Evaluation", {
  data: () => [
    { input: "What is 2+2?", expected: "4" },
    { input: "What is the capital of France?", expected: "Paris" },
  ],
  task: async (input) => {
    const response = await client.chat.completions.create({
      model: "mistral-large-latest",
      messages: [{ role: "user", content: input }],
    });
    return response.choices[0].message.content;
  },
  scores: [
    {
      name: "accuracy",
      scorer: (args) => (args.output === args.expected ? 1 : 0),
    },
  ],
});

To learn more about tool use, multimodal support, attachments, and masking sensitive data with Mistral, visit the customize traces guide.

Models and capabilities

ModelMultimodalReasoningMax inputMax outputInput $/1MOutput $/1M
magistral-medium-latest40,96040,000$2.00$5.00
magistral-medium-250640,96040,000$2.00$5.00
magistral-small-latest40,00040,000$0.50$1.50
magistral-small-250640,00040,000$0.50$1.50
devstral-small-latest128,000128,000$0.10$0.30
devstral-small-2507128,000128,000$0.10$0.30
mistral-large-latest$2.00$6.00
mistral-large-2411$2.00$6.00
pixtral-large-latest$2.00$6.00
pixtral-large-2411$2.00$6.00
mistral-medium-latest$0.40$2.00
mistral-medium-2505$0.40$2.00
mistral-small-latest$0.10$0.30
mistral-small-2501$0.10$0.30
codestral-latest$0.30$0.90
codestral-2501$0.30$0.90
ministral-8b-latest$0.10$0.10
ministral-8b-2410$0.10$0.10
ministral-3b-latest$0.04$0.04
ministral-3b-2410$0.04$0.04
mistral-saba-latest$0.20$0.60
mistral-saba-2502$0.20$0.60
pixtral-12b-2409$0.15$0.15
open-mistral-nemo$0.15$0.15
open-mistral-nemo-2407$0.15$0.15
open-codestral-mamba$0.60$0.60
open-mixtral-8x22b$2.00$6.00
mistral-tiny$0.15$0.46
mistral-small$1.00$3.00
mistral-medium$2.75$8.10

On this page

Mistral - Docs - Braintrust