OCR

Optical character recognition to extract text from documents and images

Source document

                

Introduction

The AlphaEdge OCR API lets you extract text from documents, images and PDFs. This feature is optimized for high performance and accuracy.

This page guides you through using the OCR API, from the basics to advanced use cases.

Quick start

Here is a minimal example to get started with the OCR API:

Basic example

python
import requests

url = "https://api-endpoints.alphaedge-ai.com/models/alpha-digit-max/ocr"
headers = {"X-API-Key": "TA_CLE"}

with open("/chemin/image.png", "rb") as f:
    files = {"image": ("image.png", f, "image/png")}
    r = requests.post(url, headers=headers, files=files, timeout=300)

print(r.status_code)
print(r.json())
bash
curl https://api-endpoints.alphaedge-ai.com/models/alpha-digit-max/ocr \
  -H "X-API-Key: TA_CLE" \
  -F "file=@document.pdf" \
  -F "model=alphaedge-ocr-3"
javascript
import fs from "node:fs";

const form = new FormData();
form.append("image", new Blob([fs.readFileSync("/chemin/image.png")]), "image.png");

const res = await fetch("https://api-endpoints.alphaedge-ai.com/models/alpha-digit-max/ocr", {
  method: "POST",
  headers: { "X-API-Key": "TA_CLE" },
  body: form
});

console.log(res.status, await res.json());

API parameters

Here are the available parameters for the OCR API:

PARAMETER TYPE REQUIRED DEFAULT DESCRIPTION
model string Yes - The model name to use (e.g. alphaedge-ocr-3)
file File Yes - The file to process (PDF, image, etc.)

Supported file formats

The AlphaEdge OCR API supports a wide range of document formats for text extraction. Here is the full list of supported formats:

PDF documents

  • Standard PDF (.pdf) - Text documents, forms, reports
  • Scanned PDF - Document images converted to PDF
  • PDF with images - Documents containing text and images
  • Protected PDF - Password-protected documents (password required as parameter)
  • PDF/A - PDF archival format

PDF limitations: Maximum 100 pages per document, maximum size 25 MB

Images

  • JPEG/JPG (.jpg, .jpeg) - Document photos, screenshots
  • PNG (.png) - Images with transparency, high quality captures
  • TIFF/TIF (.tiff, .tif) - High resolution scanned documents
  • BMP (.bmp) - Bitmap images
  • WEBP (.webp) - Modern compressed format
  • GIF (.gif) - Animated images (first frame extracted)

Image limitations: Maximum resolution 4096x4096 pixels, maximum size 25 MB per file

Microsoft Office documents

  • Word (.doc, .docx) - Microsoft Word text documents
  • Excel (.xls, .xlsx) - Spreadsheets (extraction of cells with text)
  • PowerPoint (.ppt, .pptx) - Presentations (extraction of text from slides)

OpenDocument documents

  • ODT (.odt) - OpenDocument text documents
  • ODS (.ods) - OpenDocument spreadsheets
  • ODP (.odp) - OpenDocument presentations

Other formats

  • RTF (.rtf) - Rich Text Format
  • TXT (.txt) - Plain text files
  • HTML (.html, .htm) - Web pages (extraction of visible text)
  • EPUB (.epub) - E-books

Recommendations

  • For scanned documents: use high resolution TIFF or PNG images (minimum 300 DPI)
  • For text documents: PDF or DOCX give the best results
  • For forms: PDF with form fields or high resolution images
  • Avoid very low resolution images (< 150 DPI) for best results

Response format

The OCR API returns a response in JSON format. Here is an example response structure:

json
{
  "id": "req_abc123",
  "object": "ocr.response",
  "created": 1677652288,
  "model": "alphaedge-ocr-3",
  "text": "Le texte extrait depuis le document...",
  "usage": {
    "total_tokens": 60
  }
}

Advanced examples

Extraction with structured format

Extract structured data from a form:

python
import requests

url = "https://api-endpoints.alphaedge-ai.com/models/alpha-digit-max/ocr"
headers = {"X-API-Key": "TA_CLE"}

with open("/chemin/image.png", "rb") as f:
    files = {"image": ("image.png", f, "image/png")}
    r = requests.post(url, headers=headers, files=files, timeout=300)

print(r.status_code)
print(r.json())

Error handling

Here is how to handle errors properly:

python
import requests

url = "https://api-endpoints.alphaedge-ai.com/models/alpha-digit-max/ocr"
headers = {"X-API-Key": "TA_CLE"}

with open("/chemin/image.png", "rb") as f:
    files = {"image": ("image.png", f, "image/png")}
    r = requests.post(url, headers=headers, files=files, timeout=300)

print(r.status_code)
print(r.json())
javascript
import fs from "node:fs";

const form = new FormData();
form.append("image", new Blob([fs.readFileSync("/chemin/image.png")]), "image.png");

const res = await fetch("https://api-endpoints.alphaedge-ai.com/models/alpha-digit-max/ocr", {
  method: "POST",
  headers: { "X-API-Key": "TA_CLE" },
  body: form
});

console.log(res.status, await res.json());

Use cases

Here are some common use cases for the OCR API:

1. Document digitization

Convert paper documents to digital text for archiving and search.

2. Form data extraction

Automatically extract information from scanned forms (invoices, contracts, etc.).

3. Text recognition in images

Extract text from images, screenshots or document photos.

Limitations and best practices

Limitations

  • File size : Files must not exceed 25 MB
  • Supported formats : PDF, PNG, JPG, JPEG, TIFF, BMP, WEBP, GIF, DOC, DOCX, XLS, XLSX, PPT, PPTX, ODT, ODS, ODP, RTF, TXT, HTML, EPUB
  • Rate limiting : 60 requests per minute by default (can be increased based on your plan)
  • Tokens : 4096 token limit for combined prompts and responses
  • PDF pages : Maximum 100 pages per document

Best practices

  • Use high resolution images (minimum 300 DPI) for best results
  • For scanned documents, ensure contrast is sufficient
  • Handle errors properly with try/except blocks
  • Implement a retry mechanism to handle temporary errors
  • Cache results when possible to reduce costs
  • Monitor your usage to avoid exceeding your limits

Available models

To view all available OCR models with their detailed specifications, visit the Our models and filter by type.