OCR API Documentation

This documentation provides details on how to use our OCR API to extract text from images with multilingual support.

API Overview

The Arabic OCR service provides a REST API for extracting text from images with support for multiple languages, including Arabic.

Base URL: http://ocr.nusrv.com/

Key Features

  • Support for Arabic and multiple other languages
  • Language combinations (ara+eng, ara+fra, etc.)
  • Support for both image files and PDF documents
  • Multi-page PDF processing with page separation
  • Image preprocessing for better OCR accuracy
  • Clean JSON response format
  • Secure API key authentication
  • Rate limiting (100 requests per day per API key)

Authentication

Most API endpoints require authentication using an API key.

Getting an API Key

Visit the API Key Management page to generate your API key.

Using Your API Key

You can include your API key in requests using one of these methods:

1. As a Request Header (Recommended)
X-API-Key: YOUR_API_KEY
2. As a Query Parameter
?api_key=YOUR_API_KEY
Note: The /api/languages endpoint is public and does not require authentication.

Rate Limits

Each API key is limited to 100 requests per day. When your limit is exceeded, requests will return a 429 Too Many Requests status code.

Available Languages

The following languages and language combinations are available for OCR:

Language Code Language Name
ara Arabic
eng English
fra French
ita Italian
deu German
spa Spanish
por Portuguese
rus Russian
tur Turkish
ara+eng Arabic + English
ara+fra Arabic + French
ara+ita Arabic + Italian
ara+deu Arabic + German
ara+spa Arabic + Spanish
eng+fra English + French

Get Available Languages

GET /api/languages

Retrieves a list of all available language options for OCR processing.

Response
{
    "status": "success",
    "languages": {
        "ara": "Arabic",
        "eng": "English",
        "fra": "French",
        "ita": "Italian",
        "deu": "German",
        "spa": "Spanish",
        "por": "Portuguese",
        "rus": "Russian",
        "tur": "Turkish",
        "ara+eng": "Arabic + English",
        "ara+fra": "Arabic + French",
        "ara+ita": "Arabic + Italian",
        ...
    }
}

OCR Processing

POST /api/ocr

Submit an image for OCR text extraction.

Request

Content-Type: multipart/form-data

Parameters
Name Type Required Description
image File Yes The image or PDF file to process (JPG, PNG, GIF, BMP, TIFF, PDF)
lang String No Language code(s) for OCR processing (default: eng)
For multiple languages, use + separator (e.g., ara+eng)
Successful Response (200 OK)
{
    "status": "success",
    "result_id": "550e8400-e29b-41d4-a716-446655440000",
    "text": "مرحبا بالعالم\nHello world",
    "language": "ara+eng"
}
Error Response (400 Bad Request)
{
    "status": "error",
    "message": "No image file provided"
}
Example Request (cURL)
curl -X POST "http://ocr.nusrv.com/api/ocr" \
    -H "X-API-Key: YOUR_API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "lang=ara+eng"
Example Request (JavaScript)
const formData = new FormData();
formData.append('image', imageFile);
formData.append('lang', 'ara+eng');

fetch('http://ocr.nusrv.com/api/ocr', {
    method: 'POST',
    headers: {
        'X-API-Key': 'YOUR_API_KEY'
    },
    body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Retrieve OCR Results

GET /api/results/{result_id}

Retrieve a previously processed OCR result using its result ID.

Path Parameters
Name Type Required Description
result_id String Yes The unique identifier returned from a successful OCR request
Successful Response (200 OK)
{
    "status": "success",
    "result": {
        "text": "مرحبا بالعالم\nHello world",
        "language": "ara+eng",
        "filename": "example.jpg"
    }
}
Error Response (404 Not Found)
{
    "status": "error",
    "message": "Result not found"
}
Example Request (cURL)
curl -X GET "http://ocr.nusrv.com/api/results/550e8400-e29b-41d4-a716-446655440000"

Best Practices

For Best OCR Results

  • Use high-resolution images with good contrast
  • Choose images with clean white backgrounds and black text
  • Select the correct language or language combination
  • Ensure text is properly oriented in the image
  • Avoid using images with complex backgrounds or watermarks
  • Use well-lit images without shadows over the text

API Usage Tips

  • Store the result_id to retrieve results later if needed
  • Implement error handling to manage failed OCR requests
  • For Arabic + another language, always put "ara" first in the combination
  • Keep image sizes reasonable (less than 5MB) for faster processing