OCR API for Handwriting and Tables: Any Image to Text and Markdown
OCR API tutorial: extract text from photos, scans and handwritten notes with Python, get tables as Markdown and translate them in the same call.
OCR on a clean scan of printed text has been a solved problem for years. The images people actually send are something else: a phone photo of a receipt, a page of handwritten notes, a menu shot at an angle, a screenshot with two columns and a table. Classic engines return the characters but lose the structure, and on handwriting they often return noise.
An OCR API built on a vision model reads those images the way a person does: handwriting, reading order, rows of a table. It brings its own risk, though: a model that cannot read a word may write a plausible one. This article shows how the Image to Text OCR API handles both sides, with the plain text and a Markdown version that keeps the layout, and an explicit [illegible] where a guess would otherwise go.
Classic OCR, cloud OCR and vision-model OCR compared
| Tesseract (open source) | Cloud OCR services | Vision-model OCR (this API) | |
|---|---|---|---|
| Printed text | Good on clean scans | Good | Good |
| Handwriting | Weak: trained for print | Supported by the main providers | Yes, cursive included |
| Tables | Text only, structure lost | Separate table features on document products | Markdown tables in the same response |
| Reading order on complex layouts | Depends on page segmentation | Lines and blocks you reassemble | Returned in reading order |
| Word bounding boxes | Yes | Yes | No |
| Typical failure | Garbled characters | Misread characters | A plausible word where the image is unreadable |
| Price per image | Free, on your own servers | $0.0022 to $0.0026 for classic OCR APIs | About $0.0045 on PRO |
The last failure mode is the one to design against. The model behind this API is instructed to transcribe exactly: no translating, correcting, summarising or describing, one item per line with its price, and [illegible] for anything it cannot read. Text inside the image is treated as content, never as an instruction. That narrows the risk without removing it, which is why the examples below check the output wherever they can.
Extract text from a receipt photo with the OCR API in Python
POST /v1/ocr/image takes a JSON body with the direct link to an image. The photo here is a public-domain receipt from a supermarket in Rotterdam, from Wikimedia Commons:
import requests
HOST = "image-to-text-ocr-handwriting-tables-ai.p.rapidapi.com"
API = f"https://{HOST}/v1/ocr"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
image_url = (
"https://upload.wikimedia.org/wikipedia/commons/6/69/"
"Sahan_Supermarket_receipt%2C_Hillegersberg%2C_Rotterdam_%282021%29_01.jpg"
)
response = requests.post(
f"{API}/image", headers=HEADERS, json={"url": image_url}, timeout=60
)
response.raise_for_status()
result = response.json()
print(result["languages"], result["handwriting"])
print(result["markdown"])
The same call with curl:
curl -X POST "https://image-to-text-ocr-handwriting-tables-ai.p.rapidapi.com/v1/ocr/image" \
-H "X-RapidAPI-Key: YOUR_API_KEY" \
-H "X-RapidAPI-Host: image-to-text-ocr-handwriting-tables-ai.p.rapidapi.com" \
-H "Content-Type: application/json" \
-d '{"url": "https://upload.wikimedia.org/wikipedia/commons/6/69/Sahan_Supermarket_receipt%2C_Hillegersberg%2C_Rotterdam_%282021%29_01.jpg"}'
The real response took 6.8 seconds. text and markdown are cut here:
{
"source": "https://upload.wikimedia.org/wikipedia/commons/6/69/Sahan_Supermarket_receipt%2C_Hillegersberg%2C_Rotterdam_%282021%29_01.jpg",
"mime_type": "image/jpeg",
"languages": ["nl"],
"handwriting": false,
"has_text": true,
"text": "SAHAN Supermarkt\nBergweg 170\n3036 BL Rotterdam\n…\nOmschrijving\tBedrag\nMIRAS OLIJFOLIE (GLAS) 1L\t3,99\nMERAY TRAKYA POMPOENPIT 200\t1,99\n…",
"markdown": "SAHAN Supermarkt\nBergweg 170\n3036 BL Rotterdam\n…\n| Omschrijving | Bedrag |\n| :--- | :--- |\n| MIRAS OLIJFOLIE (GLAS) 1L | 3,99 |\n…"
}
And the markdown value of the same response, printed, with one line (the cashier's first name) removed:
SAHAN Supermarkt
Bergweg 170
3036 BL Rotterdam
Tel: 010-265.33.99
KASSABON
Nummer 2-00005155
Datum: 26/01/2021
| Omschrijving | Bedrag |
| :--- | :--- |
| MIRAS OLIJFOLIE (GLAS) 1L | 3,99 |
| MERAY TRAKYA POMPOENPIT 200 | 1,99 |
| PINAR POMPOENPITTEN 200G | 1,99 |
| ULKER PETIBOR BISKUVI 1KG | 2,49 |
| BROOD SIMIT | 3,75 |
| * 5 x 0.75 | |
| TOTAAL Incl: | 14,21 |
| :--- | ---: |
| PIN Betaling | 14,21 |
| Teruggave | 0,00 |
| BTW Bedrag: | 1,17 |
6 Artikel / 9 Stuks
D u wel en tot ziens
Every price stayed on the row of its item, which is what a receipt-scanning app needs and what column-by-column OCR tends to break. The quantity line 5 x 0.75 sits under the bread it explains. Numbers keep the Dutch decimal comma, as printed. And the closing line comes back as D u wel en tot ziens, not silently completed into the expected Dank u wel: the API copies what it reads rather than what it thinks the receipt meant.
In text, the same content is plain, with table cells separated by tabs. Use text for search indexes and NLP, markdown when the structure matters.
Turn Markdown tables back into rows
Markdown tables are easy for a model to produce and for code to parse. This function returns every table of a response as a list of rows, skipping the alignment line:
def markdown_tables(markdown: str) -> list[list[list[str]]]:
tables, current = [], []
for line in markdown.splitlines():
line = line.strip()
if line.startswith("|") and line.endswith("|"):
cells = [cell.strip() for cell in line[1:-1].split("|")]
if all(cell and set(cell) <= set(":-") for cell in cells):
continue # the | :--- | ---: | alignment row
current.append(cells)
elif current:
tables.append(current)
current = []
if current:
tables.append(current)
return tables
items, totals = markdown_tables(result["markdown"])
header, *rows = items
def amount(value: str) -> float:
return float(value.replace(",", "."))
lines_sum = round(sum(amount(price) for _, price in rows if price), 2)
total = amount(dict(totals)["TOTAAL Incl:"])
print(lines_sum, total, lines_sum == total) # 14.21 14.21 True
On this receipt the five prices add up to the printed total, so the reading can be trusted. The check is worth keeping in any receipt pipeline: when a sum does not match, a person looks at the image. If what you need is the accounting record itself (supplier, VAT number, tax lines, totals checked by code), the invoice OCR walkthrough covers the dedicated parser.
Handwriting OCR: notes, letters and lists
Handwriting is where vision models pull away from classic engines. The same endpoint reads it; handwriting: true in the response tells you the page was written by hand. Here, a handwritten German shopping list (photo by Pittigrilli, CC BY-SA 4.0, Wikimedia Commons), translated into English in the same call:
payload = {
"url": "https://upload.wikimedia.org/wikipedia/commons/5/5c/Handwritten_shopping_list_in_German.jpeg",
"translate_to": "English",
}
result = requests.post(f"{API}/image", headers=HEADERS, json=payload, timeout=60).json()
The real response, in full except for the two markdown values, identical to text on a plain list:
{
"source": "https://upload.wikimedia.org/wikipedia/commons/5/5c/Handwritten_shopping_list_in_German.jpeg",
"mime_type": "image/jpeg",
"languages": ["de"],
"handwriting": true,
"has_text": true,
"text": "Salami\nChorizo\nKräuter\nRosen + 4\nMarmelade\nLeberwurst\nStumpfkerzen\nBrauner Zucker\nSchwarze Tücher\nWC-Hänger\nLachs\nSa. Süßkram\nSalbe\nKandis\nkeine Gemüsekonserve / Mais\nKäse\nSuppe",
"translation": {
"language": "English",
"text": "Salami\nChorizo\nHerbs\nRoses + 4\nJam\nLiverwurst\nPillar candles\nBrown sugar\nBlack cloths\nWC-hanger\nSalmon\nSat. Sweets\nSage\nRock candy\nno canned vegetables / corn\nCheese\nSoup"
}
}
Seventeen lines of handwriting came back in 6.1 seconds, umlauts and ß included. The translation shows the limit of translating a list without context: Salbe means ointment in German (sage is Salbei), yet it came back as "Sage". The German transcription is the record; treat the translation as a convenience.
On a handwritten recipe card, from the API's documentation, line breaks, fractions and the writer's own braces survive:
Orange Cake.
1 cup white Sugar
1/2 " Crisco (some butter)?
2 Eggs.
1/2 cup sour cream
Juice of one small Calif. Orange {Wash well}
...
Bake in Angel food cake tin grease well
and lightly flour tin {400° for 40 min}
For the best results, photograph the page flat, in good light, filling the frame, one page per image. Modern handwriting reads well; centuries-old scripts are best effort, and the words nobody could read come back as [illegible]. Search for that marker to route a page to a person.
Translate the extracted text in the same call
translate_to takes a language name or code ("English", "fr"). The response then carries a translation object with the same markdown and text pair, tables kept, numbers, codes and proper names left as they are. It costs one more credit, billed only when a translation actually came back. On the receipt above, the documented English translation reads | MIRAS OLIVE OIL (GLASS) 1L | 3.99 |: product names are translated where they are words, and the decimal comma becomes a point in English.
Process a folder of images with retries
Images on disk go to POST /v1/ocr/image/upload as multipart/form-data. The script below reads a folder, writes one Markdown file per image, and skips images without text:
import pathlib
import time
import requests
HOST = "image-to-text-ocr-handwriting-tables-ai.p.rapidapi.com"
API = f"https://{HOST}/v1/ocr"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
SUFFIXES = {".jpg", ".jpeg", ".png", ".webp", ".heic", ".gif", ".bmp", ".tif", ".tiff"}
def ocr(path: pathlib.Path, attempts: int = 3) -> dict:
for attempt in range(attempts):
try:
with path.open("rb") as f:
r = requests.post(
f"{API}/image/upload",
headers=HEADERS,
files={"file": (path.name, f)},
timeout=60,
)
except (requests.Timeout, requests.ConnectionError):
r = None
if r is not None and r.status_code == 429:
raise SystemExit("Daily limit reached: resets at 00:00 UTC.")
if r is not None and r.status_code < 500:
return r.json() # a result, or {"error": {...}} for a 400
time.sleep(3 * 2**attempt) # 503: not billed, try again
return {"error": {"code": "gave_up"}}
out = pathlib.Path("ocr")
out.mkdir(exist_ok=True)
for path in sorted(pathlib.Path("scans").iterdir()):
if path.suffix.lower() not in SUFFIXES:
continue
result = ocr(path)
if "error" in result:
print(path.name, result["error"]["code"])
elif not result["has_text"]:
print(path.name, "no text")
else:
(out / f"{path.stem}.md").write_text(result["markdown"], encoding="utf-8")
An image without any text is not an error. A photo of a single banana, from the same session:
{
"source": "https://upload.wikimedia.org/wikipedia/commons/8/8a/Banana-Single.jpg",
"mime_type": "image/jpeg",
"languages": [],
"handwriting": false,
"has_text": false,
"text": "",
"markdown": ""
}
The image was read, so it uses its credit; filter such images upstream if your input has many of them. Other details that matter in production:
- Formats. PNG, JPEG, WEBP and HEIC (the iPhone default) are sent as they are; GIF, BMP, TIFF and images over 7 MB are converted to JPEG, at most 3,072 pixels on the long side, which keeps small print readable.
- File type. It is detected from the file's first bytes, not the extension or the
Content-Typeheader, so a PNG named.jpgstill works and a PDF renamed.pngis refused withunsupported_file. - Size. Up to 20 MB per image, by link or upload.
- Timing. About 3 to 8 seconds per image, a little more with a translation; run a few in parallel for large batches.
What it costs
One credit per image, two with a translation; failed calls are not billed.
| Plan | Price per month | Credits | In practice |
|---|---|---|---|
| BASIC | Free, no card | 3 per day | 3 images a day to test |
| PRO | $4.99 | 1,100 | 1,100 images (about $0.0045 each) |
| ULTRA | $14.99 | 3,500 | 3,500 images |
| MEGA | $49.99 | 11,000 | 11,000 images |
Beyond the quota, paid plans continue at $0.05 per credit. Classic OCR APIs cost less, $0.0022 to $0.0026 an image, and remain the right choice for clean printed scans. AI and handwriting OCR APIs charge $0.004 to $0.02 an image; Pen to Print, a handwriting OCR API with over 2,000 subscribers on RapidAPI, charges $0.02. The same endpoints are also listed on RapidAPI as Handwriting OCR - Handwritten Notes to Text, at the same prices. Plans are on the API page, parameters in the reference.
Run it without code on Apify
The same engine runs as an Apify Actor, Image to Text OCR - Handwriting & Tables. Paste image links or the dataset ID of another actor (an Instagram, product or real-estate scraper), optionally set a translation language, and export one row per image to CSV, Excel or JSON. It charges $0.004 per image read and $0.004 per translation; images that cannot be read are not charged.
What the OCR API does not do
- No bounding boxes. Text comes back in reading order with its layout as Markdown, not with pixel coordinates. For redaction or highlighting on the image, use an engine that returns word boxes.
- No image descriptions. It transcribes text only; a picture without text returns
has_text: false. - No PDFs. One image per call. Digital and scanned PDFs go to the PDF to Text API, page by page.
- No typed fields. It returns text, not
{"date_of_birth": ...}. For forms, the Form to JSON API maps a page to the fields you name. - No guarantee on unreadable input. Blurred, cropped or very old handwriting is best effort;
[illegible]marks what could not be read, and a check like the receipt sum above catches the rest.
Frequently asked questions
How do I extract text from an image with Python?
Send the image URL to POST /v1/ocr/image, or the file as multipart to /v1/ocr/image/upload, with requests, and read text (plain, in reading order) or markdown (headings, lists and tables kept) from the JSON response.
Can OCR read handwriting?
Classic engines such as Tesseract are trained for print and do poorly on it. Vision-model OCR reads clear handwriting well, cursive included. This API flags handwritten pages with handwriting: true and marks unreadable words [illegible] instead of guessing.
How do I extract a table from an image?
Ask for Markdown: tables come back as Markdown tables with each value on its row. Split the lines on | and skip the alignment row to get a list of rows, as in the parser above, then check totals where the document prints them.
Does the OCR API return bounding boxes?
No. It returns the text in reading order and the layout as Markdown, not coordinates. If you need to draw boxes on the image, use an OCR engine that returns word positions.
Are uploaded images stored?
No. Images are downloaded or received, read and discarded; neither the image nor the text is kept by the API. The AI provider may retain requests temporarily for abuse monitoring.
Get started
Image to Text OCR API
AI OCR for images: handwriting, receipts, documents to text and Markdown tables. Multilingual.
- OCR
- Handwriting Recognition
- Computer Vision
- Python
- Document Processing




