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
BRAINTRUST_API_KEY.@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.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 withwrapMistral(). 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.completeandmistral.chat.stream), with messages and request parameters as input; response choices and token usage as output. - Mistral Agents call spans (
mistral.agents.completeandmistral.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, andmistral.classifiers.moderateChat), with input text or messages as input; classification results as output. - Fill-in-the-middle completion spans (
mistral.fim.completeandmistral.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.