node-red-contrib-mistral 0.1.1
Node-RED nodes for the Mistral AI API: chat (text + vision + streaming), embeddings, and OCR.
node-red-contrib-mistral
Node-RED nodes for the Mistral AI API — chat completions (with vision and streaming), embeddings, and OCR.
Table of contents
Install
From the Node-RED editor:
- Open the palette manager (hamburger menu → Manage palette).
- Switch to the Install tab.
- Search for
node-red-contrib-mistraland click Install.
Or from the command line in your Node-RED user directory (typically ~/.node-red):
npm install node-red-contrib-mistral
Then restart Node-RED. Requires Node.js ≥ 18 and Node-RED ≥ 3.0.
Quick start
- Drag a mistral chat node onto your flow.
- Double-click it. In the Server field, click the pencil to create a new mistral-config entry.
- Paste your Mistral API key (get one at console.mistral.ai) and save.
- Wire an inject node (string payload) → mistral chat → debug.
- Deploy, click inject, watch the response in the debug sidebar.
The config node is shared across all Mistral nodes — set it up once, reuse it everywhere.
Nodes
mistral-config
Holds the API key (stored encrypted in Node-RED's credentials store) and base URL. Not visible in the palette — it's only accessible from the editor panel of action nodes via the Server dropdown.
| Field | Default | Notes |
|---|---|---|
| API Key | — | Required. Stored encrypted. |
| Base URL | https://api.mistral.ai/v1 |
Override for proxies or self-hosted gateways. |
mistral-chat
Calls POST /chat/completions. Supports text, vision (image inputs), and streaming.
Inputs
| Property | Type | Description |
|---|---|---|
msg.payload |
string | ChatMessage[] |
User prompt as string, or full conversation array. |
msg.image |
string | string[] |
Optional. Image URL(s) or data: base64. Requires a vision model (e.g. pixtral-large-latest). |
msg.model |
string |
Optional. Override the configured model. |
msg.temperature |
number |
Optional. |
msg.max_tokens |
number |
Optional. |
msg.stream |
boolean |
Optional. Force streaming on/off for this call. |
Outputs (non-streaming)
| Property | Type |
|---|---|
msg.payload |
string — assistant reply |
msg.mistral |
full API response (id, model, choices, usage) |
msg.complete |
true |
Outputs (streaming) — one msg per chunk plus a final summary:
| Property | Chunks | Final |
|---|---|---|
msg.payload |
delta text | full accumulated text |
msg.complete |
false |
true |
msg.mistral |
— | last SSE event with usage |
mistral-embeddings
Calls POST /embeddings to vectorize text. Default model: mistral-embed (1024 dims).
Inputs
| Property | Type |
|---|---|
msg.payload |
string | string[] |
msg.model |
optional string override |
Outputs
| Property | Type |
|---|---|
msg.payload |
number[] if single input, number[][] if array input — aligned to input order |
msg.mistral |
full API response |
mistral-ocr
Calls POST /ocr to extract markdown from PDFs and images. Default model: mistral-ocr-latest.
Inputs
| Property | Value |
|---|---|
msg.payload |
URL string (https or data:), OR an object { document_url } / { image_url } / { url } |
The node auto-detects document vs image from the URL extension by default. You can force a type in the editor.
Outputs
| Property | Type |
|---|---|
msg.payload |
concatenated markdown across all pages |
msg.pages |
per-page array { index, markdown, images?, dimensions? } |
msg.mistral |
full API response |
Example flows
Importable JSON flows are in examples/:
- test-flow.json — exercises chat, streaming, embeddings, and OCR.
- vision-flow.json — minimal Pixtral image-description flow.
- rag-flow.json — full RAG pattern (index → embed query → retrieve → answer).
Import in Node-RED: hamburger menu → Import → select a file to import (or paste the JSON content).
⚠️ The
mistral-configID in each example may collide with an existing config in your flow. Node-RED will prompt to Replace or Copy. Choose Replace to reuse your existing config (with your saved API key), or Copy and re-attach manually.
Recipes
RAG with embeddings
The rag-flow.json example shows the canonical pattern in 6 steps:
- Index — inject array of documents →
mistral-embeddings→ function node stores{text, vec}pairs inflow.context. - Query — inject question →
mistral-embeddings(single string → single vector). - Retrieve — function node computes cosine similarity vs the stored vectors and keeps the top-K.
- Build prompt — same function node concatenates retrieved chunks into a context block.
- Generate —
mistral-chatanswers from the context with a system prompt enforcing context-grounding. - Debug — final answer + the retrieved chunks for traceability.
For production, replace the in-memory flow.context store with a proper vector database (Qdrant, pgvector, Pinecone, Chroma) — the only nodes you need from this package are mistral-embeddings and mistral-chat.
Streaming to a dashboard
For a live-typing UI:
inject → mistral-chat (stream=true) → function (route by msg.complete) → ui-template (append chunk)
→ ui-template (mark complete)
Filter chunks (msg.complete === false) to your "append" UI handler, and the final message (msg.complete === true) to a "done" handler that displays usage stats.
Contributing
Issues and pull requests welcome on the project repository.
License
MIT © Damien Lachambre