Mistral

Auto-instrument the Mistral SDK. Every chat.complete call inside an active run emits an llm_call event with model, token usage, and latency. Cost is computed server-side from the rate card.

Install / enable

Python:

pip install "agentping-sdk[mistral]"
import agentping
from mistralai.client.sdk import Mistral

agentping.init()
agentping.instrument_mistral()

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

with agentping.run("doc-translator") as r:
    reply = client.chat.complete(
        model="mistral-large-latest",
        messages=[{"role": "user", "content": "translate this paragraph"}],
    )
    r.score("confidence", 0.88)

instrument_mistral() patches Chat.complete, Chat.complete_async, and the streaming variant. Idempotent; safe to call once at module load. Supports mistralai >= 2.0.0.

TypeScript:

npm install @agentping/sdk @mistralai/mistralai
import * as agentping from "@agentping/sdk";
import { Mistral } from "@mistralai/mistralai";

agentping.init({ apiKey: process.env.AGENTPING_API_KEY });

const run = agentping.run("doc-translator");
const mistral = agentping.instrumentMistral(
  new Mistral({ apiKey: process.env.MISTRAL_API_KEY }),
  { run },
);

const reply = await mistral.chat.complete({
  model: "mistral-large-latest",
  messages: [{ role: "user", content: "translate" }],
});

await run.finish({ status: "success" });

instrumentMistral returns a wrapped client; reply.choices[0].message.content works as before.

What's captured

Model, input tokens, output tokens, and latency on every chat.complete. Embedding calls are not auto-instrumented; emit those yourself if you need them priced. If you reach Mistral through AWS Bedrock, see Bedrock; through Azure AI Studio, use the OpenAI-compatible deployment under OpenAI and set the event's provider to mistral to keep Spend buckets clean.

Streaming

Automatic. chat.stream is wrapped: events pass through untouched and one llm_call fires when the stream drains, carrying the final usage block. No manual handling needed.

Source / notes

The rate card carries Mistral's flagship and code models (mistral-large, mistral-medium, mistral-small, codestral). Open-weight models you self-host are unpriced by design; add an override with your inference cost per million tokens.