OCRAgent — pass a URL or base64 source and get markdown-ready text back.
Source must be a URL (
https://) or base64-encoded document. Local file paths are not supported. Currently only Mistral (mistral/mistral-ocr-latest) is supported.Quick Start
How It Works
| Method | Returns | Use when |
|---|---|---|
read / aread | str (markdown) | You only need plain text |
extract / aextract | Full result with pages | You need per-page markdown or metadata |
Configuration Options
OCRAgent
Agent class reference
OCRConfig
Configuration dataclass
| Option | Type | Default | Description |
|---|---|---|---|
include_image_base64 | bool | False | Include base64-encoded image bytes in the result |
pages | Optional[List[int]] | None | Specific page indexes to extract (0-indexed) |
image_limit | Optional[int] | None | Max images to process |
timeout | int | 600 | Request timeout in seconds |
api_base | Optional[str] | None | Override provider base URL |
api_key | Optional[str] | None | Override provider API key |
Common Patterns
- Specific pages
- Image URL
- Batch loop
- Async concurrency
Providers
Mistral OCR
Provider setup and model options
Best Practices
Use HTTPS URLs or base64
Use HTTPS URLs or base64
Local file paths are not supported — upload to a reachable URL or encode as base64 before calling
OCRAgent.Extract pages selectively for large PDFs
Extract pages selectively for large PDFs
Use
pages=[0, 1, 2] via OCRConfig or method kwargs to limit cost and latency on multi-hundred-page documents.Tune timeout for slow documents
Tune timeout for slow documents
Default timeout is 600 seconds. Lower it for quick image OCR; raise it for large scanned PDFs.
API key precedence
API key precedence
Pass
api_key on OCRConfig, on OCRAgent(...), or set MISTRAL_API_KEY in the environment — instance config wins over env vars.Related
Knowledge
Index extracted text for retrieval
Tools
Give agents document-processing tools

