OCR
POST /v1/ocr extracts text, tables, and layout from a PDF, JPEG, or PNG in a
single synchronous request. The response is the selected provider's native OCR
output, returned unchanged. Use GET /v1/models to find the
OCR models available to your project.
Send a document by URL
curl -X POST "https://api.llmapi.ai/v1/ocr" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mistral-ocr",
"document": {
"type": "document_url",
"document_url": "https://example.com/invoice.pdf"
}
}'
document takes one of three forms:
type |
Field |
Use for |
document_url |
document_url |
A PDF, as an http(s) URL or a data:application/pdf;base64,... URL. |
image_url |
image_url |
A JPEG or PNG, as an http(s) URL or a data:image/...;base64,... URL. |
file |
file_id |
A file uploaded earlier with POST /v1/files and purpose=ocr. |
Upload the file directly
Send multipart/form-data with a file part and a model field. Options can
be sent as individual form fields or as one JSON object in a request field.
curl -X POST "https://api.llmapi.ai/v1/ocr" \
-H "Authorization: Bearer $LLM_API_KEY" \
-F "model=mistral-ocr" \
-F "file=@invoice.pdf" \
-F "pages=0,1,2"
Reuse an uploaded file
Upload once with purpose=ocr, then reference the returned id from any
number of OCR requests in the same project:
curl -X POST "https://api.llmapi.ai/v1/files" \
-H "Authorization: Bearer $LLM_API_KEY" \
-F "purpose=ocr" \
-F "file=@invoice.pdf"
curl -X POST "https://api.llmapi.ai/v1/ocr" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "mistral-ocr", "document": {"type": "file", "file_id": "file-abc123"}}'
Request fields
| Field |
Description |
model |
Required. OCR model ID from the catalog. |
document |
Required for JSON requests. The document source, as described above. |
pages |
Zero-based page indexes to process, for example [0, 1, 2]. Omit to process the whole document. |
include_image_base64 |
Return extracted images (or cropped regions) as base64. |
image_limit, image_min_size |
Cap the number of extracted images and skip images below a minimum size. |
table_format |
markdown or html. |
extract_header, extract_footer |
Include page headers and footers in the output. |
include_blocks |
Return layout blocks alongside the text. |
confidence_scores, confidence_scores_granularity |
Return confidence scores, grouped by word, block, or page. |
document_annotation_format, bbox_annotation_format |
JSON schemas for structured extraction over the whole document or each bounding box. |
document_annotation_prompt |
Instructions for document annotation. |
need_layout_visualization |
Return layout visualization images, where supported. |
Options are model-specific. Mistral OCR models accept the full set above.
GLM-OCR models support pages (which must be a contiguous range),
include_image_base64, and need_layout_visualization, and reject most other
options with a 400 that names the parameter.
Response
The body is the provider's native OCR response. Mistral OCR models return
per-page markdown:
{
"model": "mistral-ocr-latest",
"pages": [
{
"index": 0,
"markdown": "# Invoice 1042\n\n| Item | Qty | Price |\n| --- | --- | --- |\n| ...",
"images": [],
"dimensions": { "dpi": 200, "height": 2200, "width": 1700 }
}
],
"usage_info": { "pages_processed": 1, "doc_size_bytes": 48213 }
}
GLM-OCR models return md_results, layout_details, and token usage
instead. Check the model you requested and parse the matching shape.
Limits and billing
- Supported formats are PDF, JPEG, and PNG; the type is detected from the file content.
- Uploaded files: PDF up to 50 MB, images up to 10 MB. The maximum page count per document depends on the model's provider (100 pages for some); use
pages to process large documents in parts.
- Billing depends on the model's pricing mode:
- Page-priced models charge per processed page. Requests with
document_annotation_format or bbox_annotation_format are charged at the annotated-page price.
- Token-priced models (such as GLM-OCR) charge for the prompt and completion tokens the provider reports, at the model's input and output token rates. The final charge does not depend on the page count.
- In both modes, credits are reserved up front from the page price and the number of pages requested (a default ceiling when
pages is omitted), then settled on actual usage. For token-priced models the reservation is only an estimate, so don't use it to predict the final charge.
- Provider fallback and batch OCR are not supported; each request runs synchronously on the selected model.
Errors
| Status |
Meaning |
400 |
Invalid request, unsupported format, or an option the model doesn't support. |
402 |
Insufficient credits. |
404 |
The referenced file_id doesn't exist in this project. |
413 |
File exceeds the size limit. |
502 |
The OCR provider failed or is unavailable. |
API operation: POST /v1/ocr