/api/ocr endpoint extracts plain text from invoice images or PDFs without structuring. Use this for debugging, testing model vision capabilities, or when you only need raw text.
Endpoint
Request Body
Base64-encoded image data or data URL. Required if
pdfUrl and pdfBase64 are not provided.Formats:- Bare base64:
iVBORw0KGgoAAAANS... - Data URL:
data:image/png;base64,iVBORw0KGgo...
MIME type of the image (e.g.,
image/png, image/jpeg, image/webp). Only used if imageBase64 is bare base64.Publicly accessible URL to a PDF document. Required if
imageBase64 and pdfBase64 are not provided.Base64-encoded PDF data or data URL. Required if
imageBase64 and pdfUrl are not provided.Formats:- Bare base64:
JVBERi0xLjQKJeLjz9... - Data URL:
data:application/pdf;base64,JVBERi0xLjQK...
Optional filename for PDF documents (used in OpenRouter request)
Override the default model. Examples:
openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude-3.5-sonnetOverride PDF parsing plugins. Advanced use only.Default:
Pass-through OpenRouter annotations to avoid re-parsing costs on subsequent requests
Response
Extracted raw text from the document, preserving line breaks
Error Response
Error message describing what went wrong
Example Requests
Example Response
Success (200)
Error (400)
Error (500)
Implementation Details
System Prompt
The endpoint uses this system prompt to guide text extraction:PDF Processing
For PDFs, the endpoint:- Configures the
file-parserplugin with the specified engine - Sends the PDF to OpenRouter with multi-page support
- Extracts text across all pages
OPENROUTER_PDF_ENGINE environment variable controls the parsing engine:
pdf-text(default) - Fast, text-layer extractionmistral-ocr- OCR-based, better for scanned PDFsnative- Model’s native PDF support
Model Parameters
temperature: 0- Deterministic outputresponse_format- Not enforced (plain text response)
Use Cases
Debugging
Verify what the model sees before attempting structured extraction
Format Testing
Test if your invoice format is readable by vision models
Search Indexing
Extract text for full-text search or keyword indexing
Custom Parsing
Get raw text and apply your own parsing logic
Limitations
- No schema validation or data structuring
- No reconciliation or calculation verification
- Line breaks and formatting depend on model interpretation
- Multi-column layouts may not preserve column order
Next Steps
Structured Extraction
Extract structured JSON with MyBillBook schema
V4 Schema
Advanced India GST extraction with reconciliation
