Overview
Extract text from PDF documents with intelligent detection. The API automatically determines whether your PDF contains selectable text or is a scanned document, then uses the optimal extraction method:- Text-based PDFs: Fast direct text extraction (no OCR needed)
- Scanned PDFs: Full OCR processing with Mistral Document AI
- Mixed PDFs: Handled intelligently based on content type
Authentication
All OCR endpoints require authentication via Bearer token in the Authorization header.Request
You can submit PDFs via either file upload or base64-encoded JSON.Method 1: File Upload (multipart/form-data)
Method 2: Base64 JSON
Request Parameters
| Parameter | Type | Description |
|---|---|---|
file or pdf | file/base64 | PDF file or base64-encoded PDF data |
Responses
Success Response (OCR Processing)
Success Response (Text Extraction)
text_extraction method) don’t include raw_response since they don’t use OCR processing.
Field Reference
Top-Level Fields
- success boolean — Whether text extraction succeeded overall.
- text string — Concatenated text from all processed pages (pages separated by
\n\n). - method string — Extraction method:
"mistral_document_ai"(OCR) or"text_extraction"(direct). - pages_processed integer — Number of pages actually processed.
- total_pages integer — Total number of pages in the PDF.
- pages array — Per-page results (see below).
Per-Page Fields
- page_number integer — 1-indexed page number.
- text string — Extracted text from this page.
- success boolean — Whether extraction succeeded for this page.
- error string (optional) — Error message if extraction failed for this page.
- raw_response object (optional) — Complete raw response from Mistral Document AI for this page (only for OCR-processed pages).
Raw Response Object
Theraw_response field contains the complete, unprocessed response from Mistral Document AI:
- All fields returned by the API (not just
markdown) - Original structure and formatting
- Metadata and additional information
- Useful for advanced processing or debugging
Page Management
How Pages Are Processed
The OCR API processes PDF pages sequentially (one at a time):- Text-based PDFs: Pages are extracted directly using fast text extraction
- Scanned PDFs: Each page is converted to an image (at specified DPI) and processed through OCR individually
Accessing Per-Page Results
Use thepages array to access individual page results programmatically:
Error Responses
Authentication Required
401 Unauthorized
Invalid API Key
503 Service Unavailable
Processing Error
422 Unprocessable Entity