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

# Mistral

> Wrap the Mistral client to meter and gate chat, fill-in-the-middle and agent calls, streaming included.

## Set up

Wrap an instance of `Mistral` from `@mistralai/mistralai`. The SDK recognizes it automatically.

```typescript theme={null}
import { Mistral } from '@mistralai/mistralai';

const mistral = stigg.wrap(new Mistral({ apiKey: process.env.MISTRAL_API_KEY }));

// A regular call. Usage is reported when the response arrives.
await mistral.chat.complete({
  model: 'mistral-small-latest',
  messages: [{ role: 'user', content: 'Summarize this ticket' }],
  stiggContext: { customerId: 'customer-acme', entitlement: { currencyId: 'credits' } },
});

// A streamed call. Usage is reported once, when the stream finishes.
const stream = await mistral.chat.stream({
  model: 'mistral-small-latest',
  messages: [{ role: 'user', content: 'Summarize this ticket' }],
  stiggContext: { customerId: 'customer-acme', entitlement: { currencyId: 'credits' } },
});
for await (const event of stream) {
  // show the text to the user as it arrives
}
```

Two ways of calling Mistral are **not** metered or checked:

* **Standalone functions.** Every method also exists as a function that takes the client as an argument, such as `chatComplete(client, request)` from `@mistralai/mistralai/funcs/`. These do not go through the wrapped client. Call the client's methods instead.
* **Streams read with `getReader()`.** Iterate a stream with `for await`, as above, so the SDK can meter it.

Mistral's API also follows OpenAI's format, so you can wrap an `OpenAI` client whose `baseURL` is `https://api.mistral.ai/v1` instead. Calls are then reported under `openai.*` event names, with the same metric names as below. See [OpenAI-compatible endpoints](/documentation/ai-agents/llm-wrappers/providers/openai-compatible).

## What is reported

Every response from the Mistral API includes a `usage` object with the number of tokens the call consumed. The wrapper reads it and reports it to Stigg as the metrics below. For details, see Mistral's [API reference](https://docs.mistral.ai/api/).

| Method | Event name |
| - | - |
| `chat.complete` | `mistral.chat.complete` |
| `chat.stream` | `mistral.chat.stream` |
| `chat.parse` | `mistral.chat.parse` |
| `chat.parseStream` | `mistral.chat.parseStream` |
| `fim.complete` | `mistral.fim.complete` |
| `fim.stream` | `mistral.fim.stream` |
| `agents.complete` | `mistral.agents.complete` |
| `agents.stream` | `mistral.agents.stream` |

Each method has its own event name, so a meter that filters on one does not count the others. To meter several together, filter on each name, or set one [`eventName`](/documentation/ai-agents/llm-wrappers/metering#configuring-meters-for-async-events) for them.

| Metric | What it counts |
| - | - |
| `prompt_tokens` | Input tokens |
| `completion_tokens` | Output tokens |
| `total_tokens` | All input and output tokens, as reported by the vendor |

The `Mistral` client returns usage in camelCase, such as `promptTokens`. The SDK reports it under the field names of Mistral's API, such as `prompt_tokens`, so the metrics are the same whether you use the `Mistral` client or the `OpenAI` client. `total_tokens` includes the other two, so price the total or the parts, never both.

Other Mistral APIs, such as conversations (`beta.conversations`), embeddings, OCR and audio, measure usage differently and are not metered. To meter one of them, write [your own recipe](/documentation/ai-agents/llm-wrappers/providers/custom).

Every usage field the vendor returns is also included, with a `raw.` prefix. See [How usage is reported](/documentation/ai-agents/llm-wrappers/supported-providers#how-usage-is-reported).


## Related topics

- [Supported providers and gateways](/documentation/ai-agents/llm-wrappers/supported-providers.md)
- [Amazon Bedrock](/documentation/ai-agents/llm-wrappers/providers/bedrock.md)
- [OpenAI-compatible endpoints](/documentation/ai-agents/llm-wrappers/providers/openai-compatible.md)
- [Agent SDK](/api-and-sdks/references/sdk/backend/graphql/agent-sdk.md)


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