A Singapore Government Agency Website

Optical Character Recognition (OCR)

The Document OCR API extracts all visible text from a document and returns it in markdown format, preserving some of the original formatting such as headings, tables, and lists.

When to Use OCR vs KIE

Use Case Recommended API
You need specific fields from a document (names, dates, amounts) KIE (Data Extraction)
You need all text from a document in a readable format OCR
You need to convert scanned PDFs into searchable text OCR
You need to analyse or evaluate document content KIE (Data Extraction)
You need to categorise documents by type Document Classification

Note: For most use cases, the KIE API is recommended over OCR. KIE combines OCR with LLM intelligence to return only the data you need, in the structure you define. The OCR API is best when you genuinely need all text content from a document.

How It Works

  1. You send a document (PDF or image)
  2. AISAY extracts all visible text from every page
  3. Text is returned in markdown format with basic formatting preserved

Available Models

Feature Flagship Model Local Model
Invoke with data_classification='RSN' data_classification='CCE'
Hosting Overseas Singapore
Processing speed Slightly slower Slightly faster
Supported formats PDF, JPG, TIFF, PNG PDF, JPG, TIFF, PNG

API Request

import json
import requests

# API configuration
API_KEY = "your-api-key-here"
API_URL = "https://api.aisay.tech.gov.sg/v1/parse"

# Set up the request
headers = {
    "Authorization": f"Bearer {API_KEY}"
}

files = {
    "file": open("path/to/your/document.pdf", "rb"),
    "data_classification": "RSN"  # Only "RSN" is accepted, this endpoint cannot accept "CCE"
}

# Make the API request
response = requests.post(API_URL, headers=headers, files=files)

# Process the response
if response.status_code == 200:
    result = response.json()
    print(f"OCR results: {result['parsed_document']}")
else:
    print(f"Error: {response.status_code}")
    print(response.text)

Sample Output

Given a scanned payslip, the OCR API might return:

# Payslip — January 2025

**Employee:** Tan Ah Kow
**Employee ID:** 23456
**Department:** Finance

| Description | Amount |
|---|---|
| Basic Salary | $4,500.00 |
| Overtime | $320.00 |
| CPF (Employee) | -$960.00 |
| **Net Pay** | **$3,860.00** |

See Also

Chat with me!
Bot Launcher