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

# Mistral AI

> Client-mode REST API connector for Mistral AI Chat Completions, Embeddings, OCR and moderation — MQTT into OpenAI-compatible LLM alarm triage, with an EU regional endpoint option

Technical Preview

## Overview

A client-mode connector for a **curated** slice of the [Mistral AI API](https://docs.mistral.ai/api), which uses OpenAI-compatible request shapes. Use it for IIoT / edge alarm text, operator notes and scanned shop-floor documents:

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| POST chat/completions | `POST /v1/chat/completions` | Chat Completions (e.g. `mistral-small-latest`); optional `response_format` `json_object` / `json_schema` |
| POST embeddings | `POST /v1/embeddings` | Create embeddings (`mistral-embed`) |
| (supporting) POST fim/completions | `POST /v1/fim/completions` | Fill-in-the-middle code completion (`codestral-latest`) |
| (supporting) POST moderations | `POST /v1/moderations` | Moderate raw text (`mistral-moderation-latest`) |
| (supporting) POST chat/moderations | `POST /v1/chat/moderations` | Moderate a conversation |
| (supporting) POST ocr | `POST /v1/ocr` | Document AI OCR on a PDF / image URL or base64 data URL (`mistral-ocr-latest`) |
| (supporting) GET models | `GET /v1/models` | List models (auth smoke) |
| (supporting) GET model | `GET /v1/models/{model_id}` | Retrieve one model |

Default `BASE_ADDRESS` is `https://api.mistral.ai` (no trailing slash). Topics use `ai/mistral-ai/<object>/<verb>`.

See the base guide: [REST API Connectors](/latest/lot-language/routes/rest-api-routes).

> [!NOTE]
>
> **Auth:** `Authorization: Bearer &lt;Mistral API key&gt;`. Prefer Hub secrets (`GET SECRET "MISTRAL_API_KEY"`) mapped into MQTT `api_token`. Never commit real keys.

> [!NOTE]
>
> **Request body:** Mistral rejects unknown fields in request bodies. The connector sends `{value.json.body}` as the JSON body, so publish `{"api_token": "...", "body": { ... }}`. The body has the same shape as the [OpenAI](/latest/lot-language/routes/rest-api-apps/openai) chat and embeddings requests.

> [!NOTE]
>
> Factory live smoke is **blocked** until a Mistral API key is supplied. Point secrets / MQTT JSON at your workspace before production use.

## EU data residency

* `api.mistral.ai` is Mistral's **global** endpoint. Mistral does not commit to an inference location for it.
* For inference processed in the EU, set `BASE_ADDRESS` to `https://api.eu.mistral.ai` (data centers in EU and EFTA countries). `https://api.us.mistral.ai` is the US option.
* Regional inference costs 1.1× list price, serves only models hosted in that region and does not offer Agents, Batch or Files. Call `GetModels` on the regional host before you send production traffic.
* Account data such as API keys, billing and usage analytics is not regional. See [Regional inference](https://docs.mistral.ai/inference/regional-inference) and the [Mistral Help Center](https://help.mistral.ai/en/articles/347629-where-do-you-store-my-data-or-my-organization-s-data).

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — Mistral AI
# Auth: Authorization Bearer {value.json.api_token}
# BASE_ADDRESS: https://api.mistral.ai  (EU inference: https://api.eu.mistral.ai)

DEFINE ROUTE MistralAiRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api.mistral.ai"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT PostChatCompletions
        WITH SOURCE_TOPIC "ai/mistral-ai/chat/completions/post"
        WITH DESTINATION_TOPIC "ai/mistral-ai/chat/completions/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/chat/completions"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT PostEmbeddings
        WITH SOURCE_TOPIC "ai/mistral-ai/embeddings/post"
        WITH DESTINATION_TOPIC "ai/mistral-ai/embeddings/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/embeddings"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
        WITH BODY "{value.json.body}"
```

Full deployable file: `MistralAiRestApi.lot` in the factory package (8 events, no `ADD METADATA`).

## Topics

| Event | Source topic | Destination topic |
| - | - | - |
| PostChatCompletions | `ai/mistral-ai/chat/completions/post` | `…/response` |
| PostEmbeddings | `ai/mistral-ai/embeddings/post` | `…/response` |
| PostFimCompletions | `ai/mistral-ai/fim/completions/post` | `…/response` |
| PostModerations | `ai/mistral-ai/moderations/post` | `…/response` |
| PostChatModerations | `ai/mistral-ai/chat/moderations/post` | `…/response` |
| PostOcr | `ai/mistral-ai/ocr/post` | `…/response` |
| GetModels | `ai/mistral-ai/models/list` | `…/response` |
| GetModel | `ai/mistral-ai/models/get` | `…/response` |

## Example Payloads

Alarm triage on `ai/mistral-ai/chat/completions/post`:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "api_token": "YOUR_MISTRAL_API_KEY",
  "body": {
    "model": "mistral-small-latest",
    "messages": [
      { "role": "system", "content": "You classify industrial alarms as JSON with severity, category and summary." },
      { "role": "user", "content": "High temperature on press-01" }
    ],
    "response_format": { "type": "json_object" },
    "max_tokens": 200
  }
}
```

Embeddings on `ai/mistral-ai/embeddings/post`:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "api_token": "YOUR_MISTRAL_API_KEY",
  "body": { "model": "mistral-embed", "input": ["pump vibration alarm"] }
}
```

OCR of a delivery note on `ai/mistral-ai/ocr/post`:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "api_token": "YOUR_MISTRAL_API_KEY",
  "body": {
    "model": "mistral-ocr-latest",
    "document": { "type": "document_url", "document_url": "https://example.com/delivery-note.pdf" },
    "table_format": "markdown"
  }
}
```

Model lookup on `ai/mistral-ai/models/get`:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{ "api_token": "YOUR_MISTRAL_API_KEY", "model_id": "mistral-small-latest" }
```

## Configuration

1. Set `BASE_ADDRESS` to `https://api.mistral.ai`, or to `https://api.eu.mistral.ai` when inference must stay in the EU.
2. Store a Mistral API key in Hub secrets (`MISTRAL_API_KEY`); map it into MQTT `api_token`.
3. For alarm classification: publish to `ai/mistral-ai/chat/completions/post` with `response_format` `json_object` or `json_schema`.
4. For semantic search / similarity: publish to `ai/mistral-ai/embeddings/post` with `mistral-embed`.
5. For scanned documents or camera snapshots: publish to `ai/mistral-ai/ocr/post` with a `document_url` or an `image_url` data URL.
6. Keep `"stream": false` (the default). Streamed replies are not split into MQTT messages.
7. Use `GetModels` as a cheap auth smoke before production workloads.

## References

* [Mistral AI API reference](https://docs.mistral.ai/api)
* [Chat Completions](https://docs.mistral.ai/api/endpoint/chat)
* [Embeddings](https://docs.mistral.ai/api/endpoint/embeddings)
* [FIM](https://docs.mistral.ai/api/endpoint/fim)
* [Classifiers (moderation)](https://docs.mistral.ai/api/endpoint/classifiers)
* [OCR](https://docs.mistral.ai/api/endpoint/ocr)
* [Models](https://docs.mistral.ai/api/endpoint/models)
* [Regional inference](https://docs.mistral.ai/inference/regional-inference)
* [Official OpenAPI](https://docs.mistral.ai/openapi.yaml)


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