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

# Mistral

> Route your Mistral AI requests through Metrion using the OpenAI-compatible SDK — with a one-line change.

Use Metrion as a proxy for Mistral AI. Mistral exposes an OpenAI-compatible API, so you can use the standard OpenAI SDK — only the `baseURL` changes.

## Prerequisites

* A Metrion account with your `sk-metrion-xxx` token (find it on the [Integrate page](https://www.metrion.dev/integrate))
* A Mistral API key saved in Metrion's Integrate page

## Setup

<Steps>
  ### Install the OpenAI SDK

  <CodeGroup>
    ```bash TypeScript theme={null}
    npm install openai
    ```

    ```bash Python theme={null}
    pip install openai
    ```
  </CodeGroup>

  ### Configure the client

  Set `baseURL` to Metrion's Mistral proxy and pass your `sk-metrion-xxx` token as `apiKey`. Metrion injects your Mistral key and forwards the request to `https://api.mistral.ai/v1/chat/completions`.

  <CodeGroup>
    ```typescript TypeScript theme={null}
    import OpenAI from 'openai'

    const client = new OpenAI({
      apiKey: 'sk-metrion-xxx',       // your Metrion token
      baseURL: 'https://www.metrion.dev/api/proxy/mistral',
    })
    ```

    ```python Python theme={null}
    from openai import OpenAI

    client = OpenAI(
        api_key="sk-metrion-xxx",     # your Metrion token
        base_url="https://www.metrion.dev/api/proxy/mistral",
    )
    ```
  </CodeGroup>

  ### Send a request

  <CodeGroup>
    ```typescript TypeScript theme={null}
    import OpenAI from 'openai'

    const client = new OpenAI({
      apiKey: 'sk-metrion-xxx',
      baseURL: 'https://www.metrion.dev/api/proxy/mistral',
    })

    const message = await client.chat.completions.create({
      model: 'mistral-large-latest',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'Hello, world!' }],
    })

    console.log(message.choices[0].message.content)
    ```

    ```python Python theme={null}
    from openai import OpenAI

    client = OpenAI(
        api_key="sk-metrion-xxx",
        base_url="https://www.metrion.dev/api/proxy/mistral",
    )

    message = client.chat.completions.create(
        model="mistral-large-latest",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello, world!"}],
    )

    print(message.choices[0].message.content)
    ```
  </CodeGroup>
</Steps>

## Direct HTTP

```bash theme={null}
curl https://www.metrion.dev/api/proxy/mistral/v1/chat/completions \
  -H 'Authorization: Bearer sk-metrion-xxx' \
  -H 'content-type: application/json' \
  -d '{
    "model": "mistral-large-latest",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello, world!"}]
  }'
```

## Supported models

| Model ID               | Notes                         |
| ---------------------- | ----------------------------- |
| `mistral-small-latest` | Efficient, low latency        |
| `mistral-large-latest` | Most capable Mistral model    |
| `codestral-latest`     | Optimised for code generation |

Metrion uses prefix matching, so `mistral-large-latest` resolves to `mistral-large` pricing automatically.

## Pass-through mode

To use your own Mistral key without storing it in Metrion, pass it in `Authorization: Bearer` and identify your Metrion account with the `x-metrion-token` header:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import OpenAI from 'openai'

  const client = new OpenAI({
    apiKey: process.env.MISTRAL_API_KEY,     // your Mistral key directly
    baseURL: 'https://www.metrion.dev/api/proxy/mistral',
    defaultHeaders: {
      'x-metrion-token': 'sk-metrion-xxx',   // identifies your Metrion account
    },
  })
  ```

  ```python Python theme={null}
  from openai import OpenAI
  import os

  client = OpenAI(
      api_key=os.environ["MISTRAL_API_KEY"],
      base_url="https://www.metrion.dev/api/proxy/mistral",
      default_headers={"x-metrion-token": "sk-metrion-xxx"},
  )
  ```
</CodeGroup>

<Note>
  In pass-through mode, your Mistral key is forwarded directly to Mistral's API and is never stored by Metrion.
</Note>

## Track requests by user or service

Add the optional `x-metrion-user` header to tag individual requests. These labels appear in your Metrion logs and dashboards.

<Tip>
  Use `x-metrion-user` to break down costs by team member, bot, or application — for example `"x-metrion-user": "code-review-bot"` or `"x-metrion-user": "user-77"`.
</Tip>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const client = new OpenAI({
    apiKey: 'sk-metrion-xxx',
    baseURL: 'https://www.metrion.dev/api/proxy/mistral',
    defaultHeaders: {
      'x-metrion-user': 'user-77',
    },
  })
  ```

  ```python Python theme={null}
  client = OpenAI(
      api_key="sk-metrion-xxx",
      base_url="https://www.metrion.dev/api/proxy/mistral",
      default_headers={"x-metrion-user": "user-77"},
  )
  ```
</CodeGroup>
