> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Mistral AI

> Trace Mistral AI model calls with Netra auto-instrumentation. Monitor prompts, completions, token usage, and performance metrics automatically.

<img src="https://mintcdn.com/netra/IXT7TOAHn4HQhvyF/images/integration-logos/llm-providers/mistral-ai.png?fit=max&auto=format&n=IXT7TOAHn4HQhvyF&q=85&s=c7220bc9f657a7c2a10d66a2836286ed" alt="Mistral AI" width="242" height="80" data-path="images/integration-logos/llm-providers/mistral-ai.png" />

## Installation

Install both the Netra SDK and Mistral SDK:

<CodeGroup>
  ```bash Python theme={null}
  pip install netra-sdk mistralai
  ```

  ```bash Typescript theme={null}
  npm install netra-sdk @mistralai/mistralai
  ```
</CodeGroup>

## Usage

Initialize the Netra SDK with Mistral instrumentation enabled. The SDK automatically traces all Mistral API calls once initialized.

<CodeGroup>
  ```python Python theme={null}
  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)
  ```

  ```typescript Typescript theme={null}
  import { Netra } from "netra-sdk";
  import MistralClient from "@mistralai/mistralai";

  async function main() {
    // Initialize Netra with Mistral instrumentation (must await)
    await Netra.init({
      appName: "my-ai-app",
      headers: `x-api-key=${process.env.NETRA_API_KEY}`,
      traceContent: true
    });

    // Use Mistral client as usual - all calls are automatically traced
    const mistral = new MistralClient(process.env.MISTRAL_API_KEY);

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

    console.log(response.choices[0].message.content);
  }

  main();
  ```
</CodeGroup>

### Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:

<CodeGroup>
  ```python Python theme={null}
  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="")
  ```

  ```typescript Typescript theme={null}
  const stream = await mistral.chatStream({
    model: "mistral-large-latest",
    messages: [{ role: "user", content: "Tell me a story" }]
  });

  for await (const chunk of stream) {
    if (chunk.choices[0]?.delta?.content) {
      process.stdout.write(chunk.choices[0].delta.content);
    }
  }
  ```
</CodeGroup>

### Embeddings

Embedding operations are also automatically instrumented:

<CodeGroup>
  ```python Python theme={null}
  embeddings = client.embeddings(
      model="mistral-embed",
      input=["The quick brown fox jumps over the lazy dog"]
  )

  print(embeddings.data[0].embedding)
  ```

  ```typescript Typescript theme={null}
  const embeddings = await mistral.embeddings({
    model: "mistral-embed",
    input: ["The quick brown fox jumps over the lazy dog"]
  });

  console.log(embeddings.data[0].embedding);
  ```
</CodeGroup>

### Selective Instrumentation

Control which integrations are enabled using the `instruments` or `blockInstruments` configuration:

<CodeGroup>
  ```python Python theme={null}
  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}
  )
  ```

  ```typescript Typescript theme={null}
  import { Netra, NetraInstruments } from "netra-sdk";

  // Only enable Mistral instrumentation
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    instruments: new Set([NetraInstruments.MISTRALAI])
  });

  // Or block specific instrumentations
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    blockInstruments: new Set([NetraInstruments.HTTP])
  });
  ```
</CodeGroup>

## Next Steps

* [Quick Start Guide](https://docs.getnetra.ai/quick-start/python) - Complete setup and configuration
* [Auto Instrumentation](https://docs.getnetra.ai/tracing/auto-instrumentation) - Automatic tracing for supported libraries
* [Decorators](https://docs.getnetra.ai/tracing/decorators) - Add custom tracing with `@workflow`, `@agent`, and `@task` decorators
* [Session Tracking](https://docs.getnetra.ai/tracing/session) - Track user sessions and conversations
* [Mistral Documentation](https://docs.mistral.ai/getting-started/quickstart/) - Official Mistral AI quickstart guide
