Mistral OCR Markdown
Overview
Use the bundled TypeScript CLI to convert one local PDF/image file into one markdown file via Mistral OCR.
Workflow
- Validate that the input file path exists and is a single local document.
- Resolve API key from CLI flag or environment.
- Run the CLI to upload the file, execute OCR, and write markdown output.
- Use the generated markdown file in follow-up agent steps.
Run The CLI
Use npm from scripts/.
npm install
npm run build
node dist/cli.js <input-file> [--output <output-md>]
Examples:
node dist/cli.js ../sample_files/example.pdf
node dist/cli.js /any/path/to/example.pdf --output-dir ../out
node dist/cli.js ../sample_files/example.pdf --output ../out/example.md
node dist/cli.js ../sample_files/example.png --pages 0,1,2
API Key Configuration
Provide Mistral API key in this precedence order:
--api-key <key>MISTRAL_API_KEYin environment.envfile (auto-loaded from--env-fileor nearest.envin current/parent directories)
Prefer MISTRAL_API_KEY in environment for CI/automation and .env for local development.
Output Contract
Write one markdown file.
- Keep page order.
- Insert page separators between pages.
- Preserve OCR markdown as returned by the API.
- Default output path:
./ocr-output/<input-basename>.md(relative to current working directory). - Use
--outputfor an exact file path or--output-dirfor a custom output folder.
Parameters
--model <name>: OCR model (defaultmistral-ocr-latest)--output-dir <path>: output directory when--outputis not specified--pages <csv>: zero-based page indexes--keep-uploaded-file: skip cleanup of uploaded file in Mistral storage--include-image-base64: request image payloads from OCR response
References
Read references/mistral-ocr-api.md when changing OCR request fields or response handling.