Set the MISTRAL_API_KEY environment variable to authenticate calls made using the SDK.
export MISTRAL_API_KEY=[your_key_here]
In a python file, setup the MistralAIInstrumentor and configure the tracer to send traces to Arize.
# Import open-telemetry dependenciesfrom arize.otel import register# Setup OTel via our convenience functiontracer_provider =register( space_id ="your-space-id", # in app space settings page api_key ="your-api-key", # in app space settings page project_name ="your-project-name", # name this to whatever you would like)# Import openinference instrumentor to map Mistral traces to a standard formatfrom openinference.instrumentation.mistralai import MistralAIInstrumentor# Turn on the instrumentorMistralAIInstrumentor().instrument(tracer_provider=tracer_provider)
To test, run the following code and observe your traces in Arize.
from mistralai.client import MistralClientfrom mistralai.models.chat_completion import ChatMessageclient =MistralClient()response = client.chat( model="mistral-large-latest", messages=[ChatMessage( content="Who won the World Cup in 2018?", role="user", ) ],)print(response.choices[0].message.content)