Integrations / Mistral
To trace Mistral with Tracify, record each chat call as a step and copy the token counts from the response. The mistralai library is not wrapped automatically, so this is a few lines you add once.
Your code
Mistral
Tracify
One run.
Setup
Mistral's official library plus the Tracify SDK.
pip install tracify-sdk mistralaiCreate a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."Mistral's chat.complete is not the same shape as OpenAI's, so there is no one-line wrapper. Open a step around the call, then copy the model and tokens from the response. Errors are recorded and still reach your code.
import os
import tracify
from mistralai.client import Mistral
mistral = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
def ask(prompt: str) -> str:
messages = [{"role": "user", "content": prompt}]
with tracify.span("mistral-chat", type="llm", input=messages) as step:
response = mistral.chat.complete(model="mistral-large-latest", messages=messages)
text = response.choices[0].message.content
step.set(
model="mistral-large-latest",
input_tokens=response.usage.prompt_tokens,
output_tokens=response.usage.completion_tokens,
)
step.set_output(text)
return textWrap the function that drives your agent with trace_agent. All Mistral steps inside it join one trace.
@tracify.trace_agent(name="mistral-agent")
def run(question: str) -> str:
draft = ask(question)
return ask("Improve this answer: " + draft)Run your code one time, then open the Tracing page of your project. Your Mistral call shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
The SDK wraps the OpenAI and Anthropic client shapes. Mistral's library has its own, so you record the call yourself. It is the same data, a few lines longer.
Good to know
Tracify records the tokens the provider returns. A dollar cost is shown when you give the wrapper your own rates with calculate_cost (Python) or calculateCost (TypeScript), so the number always matches your real price plan.
Full details in the documentation. All integrations are listed on the integrations page.
