Using Mistral OCR
Mistral OCR is a second PDF-to-Markdown backend, alongside Azure Document Intelligence. It converts a PDF to Markdown through Mistral's /v1/ocr endpoint so your Reaktors can process the text with AI models. Both backends live in the @operaide/document package.
Use Mistral OCR when you already run against Mistral or prefer a Mistral API key over an Azure connection. The two backends are interchangeable at the call site: only the function name and the connection type differ.
PDF conversion requires a configured Connection of type mistral-ocr. See the administrator guide for connection setup, caching, and timeout configuration.
aktorConvertPDFToMarkdownMistral
Converts a single PDF to Markdown. The PDF is passed as a URL or a base64 data string.
import { aktorConvertPDFToMarkdownMistral } from '@operaide/document';
const markdown = aktorConvertPDFToMarkdownMistral({
pdf,
connectionName,
});
| Parameter | Type | Description |
|---|---|---|
pdf | string | The PDF to convert, either a URL or a data:application/pdf;base64,... string |
connectionName | string (optional) | Name of the Mistral OCR connection. Falls back to the system default when omitted. Use 'default' for the default connection. |
Returns a string containing the Markdown representation of the PDF.
aktorConvertMultiplePDFsToMarkdownMistral
Batch-converts an array of PDFs. Each PDF is converted through the same connection.
import { aktorConvertMultiplePDFsToMarkdownMistral } from '@operaide/document';
const markdowns = aktorConvertMultiplePDFsToMarkdownMistral({
pdfs,
connectionName,
});
| Parameter | Type | Description |
|---|---|---|
pdfs | string[] | Array of PDF URLs or base64 strings |
connectionName | string (optional) | Name of the Mistral OCR connection |
Returns string[], one Markdown string per input PDF.
Example: Reaktor that converts a PDF
This Reaktor takes a PDF and returns its Markdown. The connection name is exposed as an App Setting so operators can point it at their configured connection.
import { aktorSetting, createAktorComposition, registerReaktorDefinition } from '@operaide/aktor';
import { aktorConvertPDFToMarkdownMistral } from '@operaide/document';
import { z } from 'zod';
const aktorMistralOcr = createAktorComposition('aktorMistralOcr', ({ document }) => {
const connectionName = aktorSetting(z.string().describe('Mistral OCR connection name'), 'default', 'Connection');
return aktorConvertPDFToMarkdownMistral({ pdf: document, connectionName });
});
registerReaktorDefinition({
reaktorDefinitionId: 'mistral-ocr',
label: 'Mistral OCR Demo',
description: 'Convert a PDF document to Markdown using Mistral OCR',
aktor: aktorMistralOcr,
inputSchema: z.object({
document: z.string().url().openapi({ example: 'https://example.com/document.pdf' }),
}),
outputSchema: z.string(),
});
Mistral OCR or Azure Document Intelligence
Both backends produce Markdown from a PDF and share the same call shape. Pick by the credentials you hold:
| Backend | Function | Connection type | Credential |
|---|---|---|---|
| Azure Document Intelligence | aktorConvertPDFToMarkdown | document-intelligence | Azure |
| Mistral OCR | aktorConvertPDFToMarkdownMistral | mistral-ocr | Mistral |
Switching backends is a change of function name and connection, not of your surrounding pipeline.
Common mistakes
- Calling the function without a connection. Mistral OCR needs a configured
mistral-ocrconnection. Without one, conversion fails. Set up the connection first (see the administrator guide). - Mixing up the connection type. A
document-intelligenceconnection does not work with the Mistral functions, and amistral-ocrconnection does not work withaktorConvertPDFToMarkdown. Match the function to its connection type. - Passing a single PDF to the batch function.
aktorConvertMultiplePDFsToMarkdownMistralexpects an array and returns an array. For one PDF, useaktorConvertPDFToMarkdownMistral.