OCR Config Object Structure
Overview
The ocr object allows you to configure Optical Character Recognition (OCR) settings for the application, enabling the extraction of text from images. This section provides a detailed breakdown of the ocr object structure.
There are 5 fields under ocr:
mistralModelapiKeybaseURLstrategyallowedAddresses
Notes:
- OCR is only active when
librechat.yamlhas anocrsection. SettingOCR_API_KEYalone does not turn it on. For Mistral's hosted API,strategy: "mistral_ocr"plusOCR_API_KEYin.envis enough, sinceapiKeyandbaseURLdefault to${OCR_API_KEY}and${OCR_BASEURL}(orhttps://api.mistral.ai/v1when that is unset). - OCR runs on files added as text: Upload as Text in chat and File Context in the Agent Builder. Agents also need the
ocrcapability inendpoints.agents.capabilities, which is included by default. Without it, a configured OCR strategy rejects the upload with "OCR capability is not enabled for Agents". - Which file types go to OCR is controlled by
fileConfig.ocr.supportedMimeTypes. - The default strategy is
mistral_ocr. WhenmistralModelis empty,mistral-ocr-latestis used. - Azure-deployed Mistral OCR models can be used by setting the strategy to
azure_mistral_ocr. - Google Vertex AI-deployed Mistral OCR models can be used by setting the strategy to
vertexai_mistral_ocr.- Requires the
GOOGLE_SERVICE_KEY_FILEenvironment variable to be set with service account credentials - The service key can be provided as: file path, URL, base64 encoded JSON, or raw JSON string
- Project ID and location are automatically extracted from the service account credentials
- Requires the
- Local text extraction is available via
document_parser, which extracts text from PDF, DOCX, XLS/XLSX, ODT, and ODS files up to 15 MB without any external API.- Uses
pdfjs-dist,mammoth, andSheetJSlocally, no API key or base URL needed - Only the
strategyfield is required;apiKey,baseURL, andmistralModelare ignored
- Uses
custom_ocris accepted by the schema but has no implementation yet.- Environment variable parsing is supported for
apiKey,baseURL, andmistralModelparameters.
Automatic Document Parsing (No Configuration Required)
The built-in document_parser runs automatically for agent file uploads even when no ocr block is configured in your librechat.yaml. This means PDF, DOCX, XLS/XLSX, and ODS files are parsed out of the box without any setup.
The resolution logic works as follows:
-
No
ocrconfig exists: When an agent context file is uploaded and its MIME type matches a supported document type (PDF, DOCX, Excel, ODS), thedocument_parseris used directly. No OCR capability check is required for the agent. -
ocrconfig exists: The configured strategy (e.g.,mistral_ocr) is tried first. If the configured strategy fails at runtime, thedocument_parseris used as a fallback so text extraction still succeeds for supported document types. -
Neither succeeds: If both the configured strategy and the document parser fail (e.g., the file is an image-only PDF with no embedded text), an error is returned suggesting that an OCR service is needed.
The document_parser handles text-based documents only. For image-based PDFs or scanned documents, you still need a configured OCR strategy (such as mistral_ocr) to extract text from the images within those files.
Example
ocr:
mistralModel: "mistral-ocr-latest"
apiKey: "your-mistral-api-key"
strategy: "mistral_ocr"Example with Azure Mistral OCR:
ocr:
mistralModel: "deployed-mistral-ocr-2503" # should match deployment name on Azure
apiKey: "${AZURE_MISTRAL_OCR_API_KEY}" # arbitrary .env var reference
baseURL: "https://your-deployed-endpoint.models.ai.azure.com/v1" # hardcoded, can also be .env var reference
strategy: "azure_mistral_ocr"Example with Google Vertex AI Mistral OCR:
ocr:
mistralModel: "mistral-ocr-2505" # model name as deployed in Vertex AI
strategy: "vertexai_mistral_ocr"For Vertex AI, deploy a Mistral OCR model in your Google Cloud project, create a service account that can call the Vertex AI endpoint, and point GOOGLE_SERVICE_KEY_FILE at its key. The variable accepts a file path, a URL to fetch the key from, base64-encoded JSON, or the raw JSON string:
GOOGLE_SERVICE_KEY_FILE=/path/to/service-account-key.jsonExample with local document parser (no external API needed):
ocr:
strategy: "document_parser"mistralModel
| Key | Type | Description | Example |
|---|---|---|---|
| mistralModel | String | The Mistral model to use for OCR processing. For Azure deployments, this should match your deployment name. For Google Vertex AI, this should match the model name in your deployment. | Optional. Specifies which Mistral model should be used when the strategy is set to mistral_ocr, azure_mistral_ocr, or vertexai_mistral_ocr. |
ocr:
mistralModel: "mistral-ocr-latest"For Azure deployments:
ocr:
mistralModel: "deployed-mistral-ocr-2503" # Your Azure deployment nameFor Google Vertex AI deployments:
ocr:
mistralModel: "mistral-ocr-2505" # Your Vertex AI model nameapiKey
| Key | Type | Description | Example |
|---|---|---|---|
| apiKey | String | The API key for the OCR service. Not used for Google Vertex AI (uses service account authentication via GOOGLE_SERVICE_KEY_FILE). | Optional. Defaults to the environment variable OCR_API_KEY, but only while baseURL is unset or ${OCR_BASEURL}. With any other baseURL, set apiKey explicitly. |
ocr:
apiKey: "your-ocr-api-key"baseURL
| Key | Type | Description | Example |
|---|---|---|---|
| baseURL | String | The base URL for the OCR service API. For Google Vertex AI, this is automatically constructed from the service account credentials. | Optional. Defaults to the environment variable OCR_BASEURL if not specified. |
ocr:
baseURL: "https://your-ocr-service.com/api"allowedAddresses
| Key | Type | Description | Example |
|---|---|---|---|
| allowedAddresses | Array of Strings | Trusted private host:port exemptions for OCR connect-time SSRF checks. Public destinations remain available. Entries require a port and cannot be URLs, paths, CIDR ranges, bare hosts, or public IP literals. | allowedAddresses: ["ocr.internal:8080"] |
OCR requests block private, loopback, link-local, and cloud-metadata destinations at connect time and disable redirects. allowedAddresses is an exemption list for exact trusted private host:port, private.ip:port, or [ipv6]:port targets; it does not restrict access to public destinations.
Trust exemptions carefully
Use allowedAddresses only for a private OCR service you control. An exempted hostname trusts whatever private address it resolves to on that port, so prefer a private IP literal when possible. With a forward proxy, the proxy must enforce destination SSRF policy; literal private destinations remain blocked unless explicitly exempted.
ocr:
strategy: "mistral_ocr"
baseURL: "http://ocr.internal:8080/v1"
apiKey: "${INTERNAL_OCR_KEY}"
allowedAddresses:
- "ocr.internal:8080"strategy
| Key | Type | Description | Example |
|---|---|---|---|
| strategy | String | The OCR strategy to use. | Determines which OCR service to use. Options are "mistral_ocr", "azure_mistral_ocr", "vertexai_mistral_ocr", "document_parser", or "custom_ocr". Defaults to "mistral_ocr". |
ocr:
strategy: "document_parser"Available Strategies:
mistral_ocr: Uses Mistral's OCR through the standard Mistral API.azure_mistral_ocr: Uses Mistral OCR models deployed on Azure AI Foundry. SetmistralModelto your deployment name andbaseURLto the deployment endpoint.vertexai_mistral_ocr: Uses Mistral OCR models deployed on Google Cloud Vertex AI, authenticated withGOOGLE_SERVICE_KEY_FILE.document_parser: Uses local text extraction for PDF, DOCX, XLS/XLSX, and OpenDocument files. No external API needed. Also runs automatically for agent file uploads when noocrconfig is present, and as a fallback when a configured OCR strategy fails.custom_ocr: Reserved for a custom OCR service atbaseURL. Not implemented yet.
How is this guide?