AI Gateway Document OCR

Document OCR

POST /v1/ocr reads a PDF or an image and returns its text as Markdown, one entry per page. It goes through the Forgebench gateway, so each call is budget-checked, guardrailed, metered per page and audited like any other model call.

Models

ModelReadsPricePage limit
mistral-ocr-latestPDFs and images, by HTTPS URL or inline$4 per 1,000 pages1,000 pages per document
sarvam-visionPDF, PNG and JPEG, inline only. Strong on Indian languages.₹0.50 per page, shown in USD at the daily rate30 pages per document

Add the provider's key first, as for any model. See Model providers. GET /v1/models lists OCR models with unit set to pages. A model that isn't an OCR model is refused with 422.

Send a document

The request body has a model and a document. Send the document as an HTTPS URL, or inline as a base64 data URI.

curl https://api.forgebench.ai/v1/ocr \
-H "Authorization: Bearer sk_..." \
-H "Content-Type: application/json" \
-d '{
  "model": "mistral-ocr-latest",
  "document": {
    "type": "document_url",
    "document_url": "https://example.com/invoice.pdf"
  }
}'
FieldMeaning
modelAn OCR model from the table above.
document.typedocument_url for a PDF or document, or image_url for an image. The URL goes in a field of the same name.
pagesOptional. A list of page indexes to read, starting at 0. sarvam-vision always reads the whole document and refuses this field.
languageOptional, sarvam-vision only. A locale such as hi-IN or en-IN.

The request body can be up to 28 MiB.

The response

The response is in Mistral's OCR format for both models.

{
  "pages": [
    { "index": 0, "markdown": "# Invoice 4471\n..." }
  ],
  "usage_info": { "pages_processed": 1 }
}

usage_info.pages_processed is the number of pages you're charged for.

Cost and budget

Before the call, Forgebench holds enough budget for the most pages the document could contain, then settles on pages_processed. If the document's page count can't be known up front, such as a PDF at a URL, the hold is the model's page limit, and the unused part is released when the call finishes. OCR draws down the same dollar budget as chat, with no minimum charge.

sarvam-vision runs as a job on Sarvam's side. Once Sarvam has accepted the job, it is billed even if the call ends badly. If the job takes longer than two minutes (504), its result can't be read (502), or you cancel the call, you're charged for the pages reserved for it. If Sarvam itself reports that it couldn't read the document, you're not charged. A result withheld by a guardrail is charged too, because the pages were read.

Guardrails and traces

Your workspace's output guardrails check the text of each page. They can redact it, or withhold the answer, as they do for chat. The call appears on the trace as an OCR call. An inline document is attached to the trace unless a personal data policy drops it. A document at a URL is recorded by its host only, so a signed link never reaches a trace.

Errors

StatusMeaning
401, 403The key is missing or invalid, or it can't call models (chat:write).
402A budget can't cover the call.
422Not an OCR model, a bad document, pages or language, or a file type the model can't read.
413The request body is over 28 MiB. Send a smaller file, or a URL for a mistral-ocr-latest document.
429 ocr_busyToo many OCR requests are running. Retry after the Retry-After delay.
502A sarvam-vision reply couldn't be read. If Sarvam had already accepted the job, you're charged for the reserved pages. If it hadn't, you aren't.
504A sarvam-vision job didn't finish in time.

Cookie settings

Our Cookie Policy lists every cookie and what it does.