Document Extraction API
Every document extraction provider configured in QAnswer — this deployment's own extraction, another QAnswer instance, or Mistral OCR — can be called directly to turn a document into markdown, page by page. Each provider has its own URL, with the provider's number in it; the provider's API tab shows it, ready to copy.
Endpoints
Replace PROVIDER_ID with the provider's number. /extract and its poll suit long documents; /v1/ocr answers in one request, in the Mistral OCR format.
GET https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/info
POST https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/extract
GET https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/extract/TASK_ID
POST https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/v1/ocrAuthentication
Send a QAnswer API key as a Bearer token: Authorization: Bearer YOUR_API_KEY. Create one on the API Access page. The key's owner must be allowed to use the provider and have document extraction in their plan; a key bound to another resource cannot use it.
What a provider accepts
GET /info returns what /extract would do with your document: enabled (whether it would accept one from you), the provider and model that would read it, models, formats, maxFileSizeMb, maxPages, and the prices creditsPerPage and ocrCreditsPerPage. It takes the same model and local parameters as /extract.
Extract and poll
POST /extract takes the document as a multipart upload and answers 202 with a taskId right away. Poll GET /extract/TASK_ID with the same key until status is done, with result in the /v1/ocr format, or failed, with error naming the reason.
file— the document. /info lists the formats the provider reads.doOcr— read scanned pages with OCR (default false). It needs a plan with OCR and charges the OCR price. An image is always read with OCR; the vanilla model ignores the option, and Mistral always reads with OCR.model— the model to use, one of /info's models; by default the provider's own. A QAnswer provider offers docling and vanilla, Mistral offers mistral-ocr-latest.pages— 0-based page numbers of a PDF to read, repeated: pages=0&pages=3. By default every page, up to the page limit.local— for another QAnswer instance that uses this provider as its own: the document is read here only, and a provider that would forward it again (Mistral, another instance) refuses it.
curl -X POST "https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/extract?doOcr=true&pages=0&pages=1" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@report.pdf"
# 202 {"taskId": "4f6c…"}
curl "https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/extract/4f6c…" \
-H "Authorization: Bearer YOUR_API_KEY"
# {"status": "pending"}
# {"status": "done", "result": {"pages": [{"index": 0, "markdown": "# Annual report…"}, …],
# "model": "docling", "usage_info": {"pages_processed": 2}}}
# {"status": "failed", "error": "DOCUMENT_EXTRACTION_DOCUMENT_INVALID"}Synchronous OCR (/v1/ocr)
POST /v1/ocr takes a request in the Mistral OCR format and answers with the pages (index and markdown of each), model and usage_info.pages_processed. Options docling has no use for are ignored.
- document: an object of type document_url, with the link in document_url, or of type image_url, with the link in image_url, as in the example below. The link is a public http(s) URL, which QAnswer downloads, or a base64 data URL.
- pages: a list of 0-based page numbers, or a string such as "0-3,7".
- Scanned pages are read with OCR when your plan includes it.
- The request waits up to 280 seconds. A longer extraction answers 424: cancelled without charge (DOCUMENT_EXTRACTION_STILL_RUNNING) or, once the document went to a remote provider, still running there (DOCUMENT_EXTRACTION_STILL_RUNNING_AT_PROVIDER): poll GET /extract/TASK_ID with the task id the error gives instead of sending the document again. Send long documents to /extract.
curl -X POST "https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID/v1/ocr" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": {"type": "document_url", "document_url": "https://example.com/report.pdf"},
"pages": "0-3,7"
}'The Mistral SDK works as is: set its server_url to the provider's URL, without /v1.
# pip install mistralai
from mistralai import Mistral
client = Mistral(
api_key="YOUR_API_KEY",
server_url="https://app.qanswer.ai/backend/api/providers/document-extraction/PROVIDER_ID",
)
response = client.ocr.process(
model="docling",
document={"type": "document_url", "document_url": "https://example.com/report.pdf"},
)
print(response.pages[0].markdown)Limits
| Limit | Value |
|---|---|
| File size | 100 MB; 50 MB on a Mistral provider |
| Pages per PDF | 200; other formats are read whole |
| Your documents in progress | 50 page batches, your indexing included (a 200-page PDF is 25) |
| Documents sent to Mistral or another instance | 4 at once on the deployment, 2 per user |
| /v1/ocr requests waiting | 4 per user |
| /v1/ocr wait | 280 seconds |
| document_url download | 60 seconds |
A request refused for load answers 429 with the headers Retry-After and X-Rate-Limit-Retry-After-Seconds, both 30 seconds.
Pricing
Each provider has two prices, set by an administrator on the provider's form: a price per page and a price per page read with OCR, 0.001 and 0.004 credits by default (1 € and 4 € per 1,000 pages). /info returns them as creditsPerPage and ocrCreditsPerPage. A price of 0 makes the provider free.
- Your credits, and your API key's own limit, are checked when a request is accepted (402 when they run out). The pages are charged once the extraction succeeds: a failed extraction, or one cancelled before it reached the provider, is not charged.
- A PDF or an image counts its pages. A format without pages (docx, html…) counts one page per 3,000 characters of markdown returned.
- A document read with OCR is charged the OCR price. A Mistral provider always is.
- Files indexed in an AI assistant whose default extraction provider is Mistral or another QAnswer instance are charged per page too, to the user who uploads them, at that provider's prices. When that user is out of credits, the file is read by this deployment instead.
- The charges appear on the providers' usage page and in the provider's Statistics tab.
Using another QAnswer instance
A QAnswer provider with a URL and an API key reads documents on another QAnswer instance: paste the provider URL from that instance's API tab and a key created there. The instance must be on a public host: private addresses, localhost and internal names are refused. That instance charges the key at its own prices, on top of what this deployment charges its callers.
Errors
An error answers with its status and a key naming the reason, such as DOCUMENT_EXTRACTION_FILE_TOO_LARGE.
- 400 — an invalid page selection, a model the provider does not offer, or a document_url that cannot be downloaded.
- 402 — you are out of credits, or the API key reached its credit limit.
- 403 — the provider is switched off for you, your plan does not include document extraction or OCR, or docling is turned off on this deployment (use vanilla).
- 404 — no provider with that number that you may use, or an unknown task.
- 413 / 415 — the file is too large or has too many pages (413), or the provider does not read its format (415).
- 422 — the document is damaged or unreadable, or the malware check rejected it.
- 424 — the provider (Mistral, another instance) cannot be reached or refuses its API key, or /v1/ocr ran out of time, see above.
- 429 — too many documents in progress, yours or the deployment's: retry after the delay given.