SAGEA LogoDocs & API
CookbooksOCR Cookbooks

Process Nepali Hindi and English Documents

Handle mixed Nepali, Hindi, and English documents with per-page language hints.

  • Send a language_hint per page for mixed-language PDFs
  • Compare output quality across scripts with confidence scores
  • Save per-page Markdown for downstream review

Time to complete: ~10 minutes

Prerequisites

  • A SAGEA_API_KEY exported as an environment variable
  • A mixed-language file in PDF, PNG, JPG, TIFF, or WEBP format, max 100MB, ideally 300 DPI
  • Python 3.9+ with the requests package installed
  • Set up document processing
  • ARVA OCR model card

Step 1: OCR with a language hint

Pass language_hint alongside the document to bias script recognition per page.

curl -X POST https://api.sagea.space/v1/ocr/process \
  -H "Authorization: Bearer $SAGEA_API_KEY" \
  -F model="arva-ocr" \
  -F [email protected] \
  -F output_format="json" \
  -F language_hint="ne"

ARVA OCR supports 150+ languages with 99.2% accuracy on clean 300 DPI scans.

Step 2: Compare hints per language

Run Hindi and English hints and keep the best-confidence result per page.

curl -X POST https://api.sagea.space/v1/ocr/process \
  -H "Authorization: Bearer $SAGEA_API_KEY" \
  -F model="arva-ocr" \
  -F [email protected] \
  -F output_format="json" \
  -F language_hint="hi"

Each response uses the standard shape with text, pages, confidence, blocks, and model_used set to arva-ocr.

Step 3: Save per-page output for review

Split the best result by page and write Markdown files for reviewers.

from collections import defaultdict
 
by_page = defaultdict(list)
for b in best["blocks"]:
    by_page[b["page"]].append(b)
 
for page, blocks in sorted(by_page.items()):
    blocks.sort(key=lambda x: x.get("confidence", 0), reverse=True)
    with open(f"page-{page}.md", "w") as f:
        f.write(f"# Page {page} (hint {best_hint})\n\n")
        for b in blocks:
            f.write(f"{b['text']}\n\n")
 
print(f"wrote {len(by_page)} page files")

Standard pages cost $1.00 per 1000 pages and complex pages $2.50 per 1000 pages.

Verify

ErrorCauseFix
401 UnauthorizedMissing or invalid API keyExport a valid key as SAGEA_API_KEY and retry
400 unsupported_formatFile type not in PDF, PNG, JPG, TIFF, WEBPConvert the file to PDF or PNG and retry
413 Payload Too LargeFile is over 100MBCompress or split the file, then retry
429 rate_limit_exceededToo many requests at onceBack off with retries and reduce concurrency

What's next

On this page