alOCR
Extract text from documents with advanced Arabic and English OCR. Supports PDFs and images with automatic deskewing and layout detection.
- Path
- /v1/ocr
- Key scope
- ocr
Supported file formats
PDF, JPG, PNG, TIFF, BMP, WEBP
Supports Arabic and English text extraction with automatic language detection
POSTUpload Document
Upload File for OCR
Upload a document and start OCR processing
Endpoint:
https://alapi.deep.sa/v1/ocr/upload
Request Format:
Two input modes are accepted: upload a file directly (multipart/form-data) or supply a public HTTPS URL and let the server fetch the PDF for you (application/x-www-form-urlencoded).
Mode A — File Upload: multipart/form-data
| Name | Type | Description |
|---|---|---|
file |
file | Document file: PDF, JPG, PNG, TIFF, BMP or WEBP (a TIFF is read from its first page) |
Mode B — URL Fetch: application/x-www-form-urlencoded
| Name | Type | Description |
|---|---|---|
url |
string | Public HTTPS URL of a PDF or image file. The server fetches and validates the content. |
filename |
string | Optional filename hint. Defaults to the URL path basename. |
Response (200 OK):
{
"token": "abc123xyz...",
"status": "queued",
"progress": 0,
"upload_progress": 100,
"queue_position": 1
}
Code Examples:
Send the file directly as multipart/form-data.
import requests
url = "https://alapi.deep.sa/v1/ocr/upload"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
with open("document.pdf", "rb") as f:
files = {"file": f}
response = requests.post(url, headers=headers, files=files)
result = response.json()
token = result["token"]
print(f"Job started, token: {token}")
GETJob Status
Get Job Status
Retrieve the status of an OCR job and, once it is done, its results. Poll with ?include=all to get tables, lines with their confidence, layout regions, fields and Markdown in the same response
Endpoint:
https://alapi.deep.sa/v1/ocr/jobs/{token}
Parameters:
| Name | Description |
|---|---|
include |
Optional. all, or a comma-separated list of lines, regions, tables, fields, markdown (line_order comes with lines). Once the job is done, each page carries those arrays; while it is pending or processing the parameter changes nothing, so poll this one URL. Any other value answers 400 invalid_include |
tables[].rows is the table as text: one array per row, one string per column. tables[].cells lists the cells that hold text, each with row and col (from 0), text and the lines it was read from; tables[].region is the table's region. Merged cells are not modelled. lines[].conf is the confidence in that line, from 0 to 1. page_num counts from 1; line and region indices inside a page count from 0. Every page also carries url, line_count, table_count and confidence: the mean of its lines' conf (null when it has no lines), a signal for sorting pages only; decide on lines[].conf
Status Values:
| Status | Description |
|---|---|
pending
|
Job is waiting in the processing queue |
processing
|
Document is being processed |
done
|
Processing complete. Results are in the pages array; a page that could not be read carries an error and is not charged |
failed
|
Processing failed. Check the error field for details |
Response (when status is done):
// GET /ocr/jobs/{token}?include=all
{
"filename": "invoice.pdf",
"status": "done",
"progress": 100,
"total_pages": 1,
"pages_failed": 0,
"detail": "full",
"results": {
"full_url": "/v1/ocr/jobs/abc123xyz?include=all",
"document_url": "/v1/ocr/jobs/abc123xyz/document",
"includes_available": ["lines", "regions", "tables", "fields", "markdown"]
},
"pages": [
{
"page_num": 1,
"url": "/v1/ocr/jobs/abc123xyz/1",
"text": "الصنف المبلغ\nرسوم 1,250.00",
"line_count": 4,
"table_count": 1,
"confidence": 0.962,
"lines": [
{ "id": 0, "text": "الصنف", "conf": 0.98, "box": [880, 210, 1010, 248], "region": 0 },
…
],
"tables": [
{
"region": 0,
"rows": [["الصنف", "المبلغ"], ["رسوم", "1,250.00"]],
"cells": [
{ "row": 1, "col": 1, "text": "1,250.00", "lines": [3] },
…
]
}
],
"regions": […], "line_order": […], "fields": {…}, "markdown": "| الصنف | المبلغ |\n…"
}
]
}
Code Examples:
curl "https://alapi.deep.sa/v1/ocr/jobs/YOUR_TOKEN_HERE?include=all" \
-H "Authorization: Bearer YOUR_API_KEY"
Text only (lighter)
Without include, a finished job carries each page's text and summary (detail: summary); results links to the full results
curl "https://alapi.deep.sa/v1/ocr/jobs/YOUR_TOKEN_HERE" -H "Authorization: Bearer YOUR_API_KEY"
{ "status": "done", "detail": "summary", "results": { … },
"pages": [ { "page_num": 1, "url": "/v1/ocr/jobs/abc123xyz/1", "text": "…",
"line_count": 4, "table_count": 1, "confidence": 0.962 } ] }
POSTRetry a Job
Resubmit a failed or stuck job without re-uploading the file. alAPI keeps a copy of every upload in object storage for the lifetime of the job, so retries reuse that copy. The client-facing token stays the same across retries.
Retry OCR Job
Safe to call on any job in failed state with retryable: true.
Endpoint:
https://alapi.deep.sa/v1/ocr/jobs/{token}/retry
Response (200 OK):
{
"token": "…same token you already have…",
"status": "pending",
"retry_count": 1
}
Error responses:
| Status | Meaning |
|---|---|
| 404 | Token unknown or not yours |
| 409 | Job is already done / still uploading |
| 422 | Legacy job without a retryable copy — re-upload |
| 429 | Hit retry_count cap (3 by default) |
| 502 | Upstream alOCR transport failure — safe to retry |
Tip: a background worker automatically retries failed-retryable jobs with exponential backoff. You only need to call /retry if you want to fail fast or surface an error to a user.
cURL:
curl -X POST "https://alapi.deep.sa/v1/ocr/jobs/YOUR_TOKEN_HERE/retry" \
-H "Authorization: Bearer YOUR_API_KEY"
GETGet Single Page
Get Page by Number
Retrieve one page: its text in reading order, lines, layout regions, tables, extracted fields and image links. Add ?markdown=1 for a Markdown rendering
Endpoint:
https://alapi.deep.sa/v1/ocr/jobs/{token}/{page_num}
Request Format:
| Name | Type | Description |
|---|---|---|
token |
String | Access token received from upload |
page_num |
Integer | Page number (1-indexed) |
Response (200 OK):
{
"page_num": 1,
"text": "Extracted text from this page...",
"direction": "rtl",
"lines": [{ "text": "...", "box": [40, 52, 980, 88], "conf": 0.98 }],
"regions": [{ "cls": "paragraph", "box": [40, 52, 980, 300] }],
"tables": [{ "rows": [["cell", "cell"]] }],
"fields": { "dates": [], "totals": [] },
"thumbnail": {
"url": "https://...presigned-url..."
},
"image": {
"url": "https://...presigned-s3-url..."
},
"status": "done"
}
thumbnail and image are short-lived links (valid for about an hour); request the page again for fresh ones.
Code Examples:
import requests
API_BASE = "https://alapi.deep.sa/v1"
API_KEY = "YOUR_API_KEY"
headers = {"Authorization": f"Bearer {API_KEY}"}
token = "YOUR_TOKEN_HERE"
page_num = 3
response = requests.get(
f"{API_BASE}/ocr/jobs/{token}/{page_num}",
headers=headers
)
page = response.json()
print(f"Page {page['page_num']}: {page['status']}")
print(page["text"])
Error Handling:
| Status | Description |
|---|---|
400 |
page_num must be >= 1 |
404 |
Job or page not found |
410 |
The job's results are no longer available |
GETThumbnails
Get Page Thumbnails
Retrieve page thumbnails with pagination
Endpoint:
https://alapi.deep.sa/v1/ocr/thumbnails/{token}?start=0&limit=10
Response:
{
"thumbnails": [
{
"page_num": 1,
"url": "https://...presigned-url..."
}
],
"start": 0,
"end": 10,
"total_pages": 25,
"has_more": true
}
GETPage Images
Get Full-Resolution Page Images
Retrieve paginated full-resolution page images (same pattern as thumbnails)
Endpoint:
https://alapi.deep.sa/v1/ocr/images/{token}?start=0&limit=10
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
token |
String | Yes | Access token received from upload |
start |
Integer | No | Offset to start from (default: 0) |
limit |
Integer | No | Number of images to return (default: 10, max: 50) |
Response (200 OK):
{
"images": [
{
"page_num": 1,
"url": "https://...presigned-s3-url..."
}
],
"start": 0,
"end": 10,
"total_pages": 25,
"has_more": true
}
Image links are short-lived (valid for about an hour); request the list again for fresh ones. Only pages that have been read are listed.
DELETEDelete a job
alOCR keeps a job’s files and results for 30 days after processing finishes, so you can follow running tasks and retrieve results later; then they are deleted automatically and job routes return 410 job_expired. To delete them sooner (ZDR), turn on “Automatically delete after 12 hours” in the alOCR console: files and results then become unavailable 12 hours after processing finishes. The setting applies to new uploads from the account, including API uploads. Jobs made through alRetrieval or alPlatform follow those products’ storage settings.
To delete a job sooner, call DELETE on it, even while it is still being read: the reading stops and the job is not charged. Its file, results and file name are deleted at once. The job stays in your usage and billing, without its content.
Endpoint:
curl -X DELETE https://alapi.deep.sa/v1/ocr/jobs/{token} \
-H "Authorization: Bearer YOUR_API_KEY"
Response:
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"token": "abc123xyz",
"status": "deleted",
"deleted_at": "2026-10-25T10:12:00Z"
}
410 job_deleted· every route for a deleted job answers this afterwards; deleting it again answers 200409 job_in_progress· the file is still being uploaded; delete the job once the upload has finished503 delete_incomplete· storage did not respond; the job is deleted and its data is removed automatically, or call DELETE again
POSTRead an identity document
Reads a passport, a Saudi national ID, a residence permit (iqama) or a visa and returns its fields. Send one JPG, PNG or PDF of up to 10 MB and 4 pages, as the request body or as a multipart part named file. The answer comes back in about a second, and nothing you send or get back is stored.
Available on request: the ID reader is turned on per account. Until then, calls answer 403 service_not_enabled. Contact us to turn it on.
Billed at 100 SAR per 1,000 pages on which a document was found, from your plan or your wallet. A page with no document is free. The ordinary OCR routes never return these fields.
Endpoint:
curl -X POST https://alapi.deep.sa/v1/id/read \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-binary @card.jpg
Response (200 OK):
{
"pages": [{
"page_num": 1,
"document": {
"type": "national_id",
"country": "SAU",
"sides": ["front"],
"fields": {
"id_number": "1000000008",
"name_ar": "نورة بنت عبدالرحمن أحمد",
"birth_date": "1992-04-28",
"expiry_date": "2032-01-19"
},
"confidence": { "id_number": 0.99 },
"checks": { "id_number": true },
"expired": false,
"needs_review": []
}
}]
}
type is passport, national_id, residence_permit, visa or id_card. fields holds what the document shows (names, numbers, dates in ISO order, nationality); a field it does not show is absent or null. confidence is the chance, from 0 to 1, that each field is exactly right; checks reports check digits and date agreement; document is null on a page with no identity document.
Send a read to a person when needs_review is not empty or a field's confidence is below your bar. When the page has a machine-readable zone, document.mrz carries it as read; add ?mrz=0 to leave it out.
403 service_not_enabled· the ID reader is not turned on for your account422 no_identity_document· no passport, ID card, residence permit or visa was found; not charged422 unreadable_file· the file could not be read as an image or PDF; not charged400 too_many_pages·413 file_too_large·415 unsupported_file· over 4 pages, over 10 MB, or not a JPG, PNG or PDF402 insufficient_balance· nothing left in your plan or wallet to pay for the pages502 upstream_unavailable· the reader is briefly unavailable; safe to send again, not charged
Ready to Get Started?
Generate an API key from your dashboard and start building