Skip to main content

General OCR Markdown

Convert an image or PDF into Markdown using a vision-language model, with OCR grounding returned alongside the result for each page.

Extract Markdown and OCR grounding from an image or PDF, returned as a single Markdown string per page.

Extract Markdown from a document

POST https://api.aigen.online/aiscript/general-ocr-md/v1

Request Body

NameTypeDescription
image*stringBase64-encoded image or PDF (without a data: URL prefix). Supports multi-page PDF.
grounding_textstring | string[] | objectCaller-provided OCR grounding, to be used instead of automatic OCR.
textstring | string[] | objectAlias for grounding_text.
groundingstring | string[] | objectAlias for grounding_text.
use_artata_groundingbooleanSet to false to run the VLM without automatic OCR grounding.

Normally, consumers only need to send image. The service performs OCR grounding automatically and returns it together with the Markdown result.

Response Schema

Top-level response

KeyTypeDescription
statusstringHTTP-style status code as a string, e.g. "200".
response_idstringEchoes the caller's x-aigen-request-id, or a generated ID.
errorlist[ErrorObject]List of errors. Empty on success.
datalist[PageResult]One item per page.

PageResult schema

KeyTypeDescription
markdownstringMarkdown content for the page.
page_numberintOne-based page number.
groundingGroundingObject | nullOCR grounding used as a reference by the VLM. null when automatic grounding is disabled or unavailable.

GroundingObject schema

KeyTypeDescription
bboxeslist[BboxObject]Detected text regions.
text_pagestringCombined OCR text for the page.
pageintOne-based page number.
max_pageintTotal number of pages.

BboxObject schema

KeyTypeDescription
bboxnumber[][]Four pixel-coordinate corner points.
bbox_normnumber[][]Four normalized corner points in the range 0–1.
char_pos_normnumber[]Normalized character positions within the text region.
textstringOCR text detected in the region.
confidencenumberOCR confidence score.
{
"status": "200",
"response_id": "request-001",
"error": [],
"data": [
{
"markdown": "# Document title\n\nDocument content",
"page_number": 1,
"grounding": {
"bboxes": [
{
"bbox": [
[20, 25],
[464, 25],
[464, 84],
[20, 84]
],
"bbox_norm": [
[0.0278, 0.0546],
[0.6453, 0.0546],
[0.6453, 0.1834],
[0.0278, 0.1834]
],
"char_pos_norm": [0.0, 0.0331, 0.0496],
"text": "Document title",
"confidence": 0.9953
}
],
"text_page": "Document title\nDocument content",
"page": 1,
"max_page": 1
}
}
]
}

Multi-page PDF response

For a PDF, data contains one item per page. Results are associated using page_number and grounding.page.

{
"status": "200",
"response_id": "request-002",
"error": [],
"data": [
{
"markdown": "Markdown for page 1",
"page_number": 1,
"grounding": {
"bboxes": [],
"text_page": "OCR text for page 1",
"page": 1,
"max_page": 2
}
},
{
"markdown": "Markdown for page 2",
"page_number": 2,
"grounding": {
"bboxes": [],
"text_page": "OCR text for page 2",
"page": 2,
"max_page": 2
}
}
]
}

Caller-provided grounding

Consumers may supply their own OCR grounding instead of relying on automatic OCR.

{
"image": "base64-encoded image",
"grounding_text": "Caller-provided OCR text"
}

When caller-provided grounding is used, the response contains that text in grounding.text_page. The grounding.bboxes array is empty because the caller did not provide localization data.

Example code

import requests

api = "https://api.aigen.online/aiscript/general-ocr-md/v1"
headers = {"x-aigen-key": "<key>"}
data = {"image": "<base64_string>"}

res = requests.post(api, json=data, headers=headers)
print(res.json())