OpenObserve Docs

Mistral → OpenObserve

Updated View MarkdownOpen in ChatGPTOpen in Claude

Automatically capture token usage, latency, and model metadata for every Mistral AI inference call in your Python application.

Prerequisites

  • Python 3.9+
  • A Mistral account with an API key
  • An OpenObserve account (cloud or self-hosted)
  • Your OpenObserve organisation ID and Base64-encoded auth token

Installation

pip install openobserve-python-sdk "openinference-instrumentation-mistralai==1.4.0" mistralai python-dotenv

Configuration

Create a .env file in your project root:

OPENOBSERVE_URL=https://api.openobserve.ai/
OPENOBSERVE_ORG=your_org_id
OPENOBSERVE_AUTH_TOKEN=Basic <your_base64_token>
MISTRAL_API_KEY=your-mistral-api-key

Instrumentation

Call MistralAIInstrumentor().instrument() before importing the Mistral client.

from dotenv import load_dotenv
load_dotenv()

from openinference.instrumentation.mistralai import MistralAIInstrumentor
from openobserve import openobserve_init

MistralAIInstrumentor().instrument()
openobserve_init()

import os
from mistralai import Mistral

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

response = client.chat.complete(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Explain observability in one sentence."}],
)
print(response.choices[0].message.content)

What Gets Captured

AttributeDescription
llm_model_nameModel used (e.g. mistral-small-latest)
gen_ai_response_modelModel that served the response
llm_systemmistralai
llm_providermistralai
gen_ai_usage_input_tokensPrompt token count
gen_ai_usage_output_tokensCompletion token count
gen_ai_usage_total_tokensTotal tokens consumed
openinference_span_kindLLM
operation_nameMistralClient.chat
span_statusOK or ERROR
status_messageError details if the request failed
durationRequest latency

Viewing Traces

  1. Log in to OpenObserve and navigate to Traces in the left sidebar
  2. Filter by llm_model_name to find Mistral spans
  3. Click any span to inspect token counts, model name, and latency
  4. Error spans show span_status = ERROR with the full error message in status_message

Mistral trace in OpenObserve, Waterfall view with the MistralClient.chat span attributes

Next Steps

With Mistral instrumented, every inference call is recorded in OpenObserve. From here you can compare latency across Mistral models, track token consumption over time, and set alerts on error rates.

Read More

Was this page helpful?

On this page