Skip to main content

Installation

Install both the Netra SDK and Mistral SDK:
pip install netra-sdk mistralai

Usage

Initialize the Netra SDK with Mistral instrumentation enabled. The SDK automatically traces all Mistral API calls once initialized.
from netra import Netra
from mistralai.client import MistralClient
import os

# Initialize Netra with Mistral instrumentation
Netra.init(
    app_name="my-ai-app",
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    trace_content=True
)

# Use Mistral client as usual - all calls are automatically traced
client = MistralClient(api_key=os.environ.get("MISTRAL_API_KEY"))

response = client.chat(
    model="mistral-large-latest",
    messages=[
        {"role": "user", "content": "What is observability?"}
    ]
)

print(response.choices[0].message.content)

Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:
stream = client.chat_stream(
    model="mistral-large-latest",
    messages=[{"role": "user", "content": "Tell me a story"}]
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Embeddings

Embedding operations are also automatically instrumented:
embeddings = client.embeddings(
    model="mistral-embed",
    input=["The quick brown fox jumps over the lazy dog"]
)

print(embeddings.data[0].embedding)

Selective Instrumentation

Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet

# Only enable Mistral instrumentation
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    instruments={InstrumentSet.MISTRALAI}
)

# Or block specific instrumentations
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    block_instruments={InstrumentSet.HTTPX}
)

Next Steps

Last modified on February 3, 2026