Skip to main content
Mistral AI provides language models, embeddings, and agent APIs. Braintrust traces Mistral calls and lets you run evaluations against Mistral models.

Tracing

You can trace Mistral calls through the native @mistralai/mistralai SDK (auto-instrumentation or wrapMistral()), or by routing through the Braintrust gateway using an OpenAI-compatible client.

Setup

Install the Braintrust SDK and either the native Mistral SDK, the OpenAI SDK (for the gateway path), or both, then set your API keys.
1

Install packages

2

Set environment variables

.env
If you only use the Braintrust gateway, your application code only needs BRAINTRUST_API_KEY.
Native SDK tracing requires @mistralai/mistralai v1.0.0 or later.

Auto-instrumentation

To trace Mistral calls without modifying your application code, run your app with Braintrust’s import hook to patch the native Mistral SDK at startup.
Run with the import hook:
The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

Manual instrumentation

To trace Mistral calls manually, wrap the client yourself with wrapMistral(). Use this when you want to instrument selected clients rather than patching the SDK globally.

Gateway

To route Mistral calls through the Braintrust gateway, point an OpenAI-compatible client at the gateway URL and pass your Braintrust API key. Add Mistral as an AI provider at the organization or project level first; the gateway uses your stored Mistral API key to call Mistral on your behalf.
API keys are stored as one-way cryptographic hashes, never in plaintext.

What Braintrust traces

Braintrust patches the native @mistralai/mistralai SDK and creates an LLM-typed span per call:
  • Chat completion spans (mistral.chat.complete and mistral.chat.stream), with messages and request parameters as input; response choices and token usage as output.
  • Mistral Agents call spans (mistral.agents.complete and mistral.agents.stream), with messages and request parameters as input; response choices and token usage.
  • Embedding spans (mistral.embeddings.create), with input text; output summarized as embedding length.
  • Classification and moderation spans (mistral.classifiers.classify, mistral.classifiers.classifyChat, mistral.classifiers.moderate, and mistral.classifiers.moderateChat), with input text or messages as input; classification results as output.
  • Fill-in-the-middle completion spans (mistral.fim.complete and mistral.fim.stream), with prompt as input; completion text and token usage.
  • Token usage metrics (prompt, completion, total, plus cached and reasoning tokens when the provider reports them) and request metadata (model and selected request parameters).
  • Parent-child nesting under any enclosing Braintrust span.
  • Errors captured on every call.

Tracing resources

Evals

Evaluate Mistral-powered tasks with Braintrust the same way you evaluate other model providers. The example below uses the Braintrust gateway, so the same pattern works whether you trace via the native SDK or the gateway.

Eval resources