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

# Mistral AI

> Auto-trace Mistral AI chat completions

### Installation

<Tabs>
  <Tab title="pip">
    ```bash theme={null}
    pip install "pandaprobe[mistral]"
    ```
  </Tab>

  <Tab title="uv">
    ```bash theme={null}
    uv add "pandaprobe[mistral]"
    ```
  </Tab>

  <Tab title="npm">
    ```bash theme={null}
    npm install pandaprobe @mistralai/mistralai
    ```
  </Tab>

  <Tab title="yarn">
    ```bash theme={null}
    yarn add pandaprobe @mistralai/mistralai
    ```
  </Tab>

  <Tab title="pnpm">
    ```bash theme={null}
    pnpm add pandaprobe @mistralai/mistralai
    ```
  </Tab>
</Tabs>

### Setup

<Tabs>
  <Tab title="Python">
    ```python title="Python" theme={null}
    from pandaprobe.wrappers import wrap_mistral
    from mistralai.client import Mistral

    client = wrap_mistral(Mistral(api_key="..."))
    ```
  </Tab>

  <Tab title="TypeScript">
    ```ts title="TypeScript" theme={null}
    import { Mistral } from "@mistralai/mistralai";
    import { wrapMistral } from "pandaprobe/wrappers/mistral";

    const client = wrapMistral(new Mistral({ apiKey: process.env.MISTRAL_API_KEY }));
    ```
  </Tab>
</Tabs>

<Note>
  PandaProbe traces both synchronous and asynchronous Python methods, plus the Promise-based TypeScript client.
</Note>

## Chat API

Span name: `"mistral-chat"`, SpanKind: `LLM`

```python title="Python" theme={null}
response = client.chat.complete(
    model="mistral-small-latest",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Explain recursion in one sentence."},
    ],
    temperature=0.5,
    max_tokens=200,
)
```

```ts title="TypeScript" theme={null}
const response = await client.chat.complete({
  model: "mistral-small-latest",
  messages: [
    { role: "system", content: "You are a concise assistant." },
    { role: "user", content: "Explain recursion in one sentence." },
  ],
  temperature: 0.5,
  maxTokens: 200,
});
```

**What gets traced**

* Input: `messages` list, captured directly (Mistral already speaks the universal schema)
* Output: assistant message from `choices[0].message`
* Model name (from the response body)
* Token usage
* Model parameters: `temperature`, `top_p`, `max_tokens`, `random_seed`, `safe_prompt`, `response_format`, `tool_choice`, `presence_penalty`, `frequency_penalty`, `n`, `stop`

### Streaming

```python title="Python" theme={null}
res = client.chat.stream(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Hello!"}],
)
with res as event_stream:
    for event in event_stream:
        delta = event.data.choices[0].delta
        if delta.content:
            print(delta.content, end="")
```

The TypeScript wrapper instruments the JavaScript SDK's asynchronous `chat.stream` method:

```ts title="TypeScript" theme={null}
const stream = await client.chat.stream({
  model: "mistral-small-latest",
  messages: [{ role: "user", content: "Hello!" }],
});
for await (const event of stream) {
  const content = event.data?.choices?.[0]?.delta?.content;
  if (typeof content === "string") process.stdout.write(content);
}
```

Python's `chat.stream` and `chat.stream_async`, plus TypeScript's `chat.stream`, are traced with time-to-first-token and reduced output.

## Token usage mapping

Mistral already uses our canonical names, so the mapping is the identity:

| Mistral Field | PandaProbe Field |
| - | - |
| `prompt_tokens` | `prompt_tokens` |
| `completion_tokens` | `completion_tokens` |
| `total_tokens` | `total_tokens` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.