Skip to navigation

OCR a document or image (Document AI)

View as Markdown

Relays to https://api.mistral.ai/v1/ocr, injecting the Authorization: Bearer credential. Extracts the selected pages of a PDF (or a single image) as per-page markdown, optionally with structured annotations pulled from the same pass. This is the only mounted Mistral route — every other Mistral path answers the gateway’s own 404, this one included under any other method or with a trailing slash.

Unlike the transparent routes in this spec, the body is a closed allow-set and the forwarded request is rebuilt from it:

  • model is pinned to mistral-ocr-4-0. Send it or omit it; any other value — including the mistral-ocr-latest alias — is a 400.
  • document must be a document_url chunk (optionally with a document_name) or an image_url chunk, carrying a public https URL. Mistral’s file_id chunk is denied: the shared account key behind this route would make one client’s uploaded file readable by all.
  • pages is required and selects at most 100 unique, zero-based page indices — an integer array, or a string of comma-separated indices and start-end ranges. It is the cost basis the balance preflight prices, which is why the route asks for it up front instead of defaulting to the whole document.
  • include_blocks and include_image_base64 are always forwarded as false; asking for true is a 400, as are image_limit and image_min_size, and so is any field the policy doesn’t recognize.
  • Adding document_annotation_format or bbox_annotation_format prices the whole call at the Document AI rate (5.275per1,000pages)insteadoftheOCRrate(5.275 per 1,000 pages) instead of the OCR rate (4.22 per 1,000 pages), both with the gateway’s 5.5% fee included; the two rates never stack, and document_annotation_prompt alone does not change the rate.

Mistral’s answer comes back exactly as it arrived — status, headers, and body bytes — and the charge is settled from the usage_info.pages_processed it reports. There is no retry: a second attempt is yours to make, as a separate, separately billed request.

Authentication

AuthorizationBearer

Your per-client bearer token — the API key the gateway issued to you. Present it in Authorization: Bearer <token> form. A token that is missing, unknown, or revoked draws a 401. Before the call is sent upstream the token is removed (stripped, or swapped for the upstream’s own credential); it never makes it past the gateway.

Request

The OCR request. A closed allow-set: document and pages are required, every other field below is optional, and anything not listed is rejected with a 400 before Mistral is called.

documentobjectRequired

What to read — one of the two admitted URL chunks. Mistral’s third chunk type, a file_id handle to a file on the account, is denied.

pageslist of integers or stringRequired

Which pages to read — required, and the basis for both the balance preflight and the charge. Zero-based, at most 100 unique pages per request, and each index at most 9999. A repeated or overlapping selection is refused rather than deduplicated, so a request always costs what it looks like it costs. Either spelling works: an integer array, or a string of comma-separated indices and ascending start-end ranges.

model"mistral-ocr-4-0"Optional

Pinned. Optional to send, but no other value — including the mistral-ocr-latest alias — is accepted, because an alias can re-point to a model at a different price.

table_formatenumOptional

How tables come back in the page markdown. null leaves Mistral’s own default in place.

Allowed values:
extract_headerbooleanOptional
Whether page headers are extracted alongside the body text.
confidence_scores_granularityenumOptional

Ask for per-page confidence scores. Only page (or null) is admitted; Mistral’s word granularity is denied, since a score per word multiplies the response size without changing what is metered.

Allowed values:
include_blocksfalseOptional

Always forwarded as false. Sending true is rejected rather than silently rewritten.

include_image_base64falseOptional

Always forwarded as false. Sending true is rejected rather than silently rewritten — extracted image bytes are neither metered nor buffered here.

document_annotation_formatobjectOptional

Mistral’s json_schema response format, at most 8,192 bytes serialized. Used for both document_annotation_format (fields drawn from the whole document) and bbox_annotation_format (labels for each detected figure); either one prices the call at the Document AI rate.

bbox_annotation_formatobjectOptional

Mistral’s json_schema response format, at most 8,192 bytes serialized. Used for both document_annotation_format (fields drawn from the whole document) and bbox_annotation_format (labels for each detected figure); either one prices the call at the Document AI rate.

document_annotation_promptstringOptional1-2000 characters

Plain-language instructions for the annotation pass. On its own it does not change the rate — only an annotation format does.

Response

Mistral’s own OCR result, relayed byte-for-byte — one entry per processed page, plus the usage_info.pages_processed count the charge is settled from. Fields the request asked for (document_annotation, per-image image_annotation) appear alongside; image_base64 is always null, since the gateway forwards include_image_base64: false.

pageslist of objectsOptional
One entry per processed page, in page order.
modelstringOptional

The model that ran — always the pinned OCR model.

document_annotationanyOptional

The whole-document annotation when document_annotation_format was sent, null otherwise.

usage_infoobjectOptional
Mistral's own accounting for the call.

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
404
Not Found Error