API Documentation

Learn how to integrate our OCR services into your application

Example Usage

Python Code Example

import requests

filename = "test.jpg"
api_key = ""

response = requests.post(
    "http://localhost:8000/api/ocr/trocr",
    headers={"Bearer": api_key},
    files={"image": open(filename, "rb")},
)

if response.status_code == 200:
    result = response.json()
    print(
        f"""
          Text: {result['text']}
          Confidence: {result['confidence']}
          Language: {result['language']}
          Language Confidence: {result['languageConfidence']}
          Processing Time: {result['processingTime']}ms
        """
    )
else:
    print(f"Error: {response.reason}")

Example Response

{
        "text": "Hello world!",
        "confidence": 0.76,
        "language": "en",
        "languageConfidence": 0.98,
        "processingTime": 19.123
}

Available Endpoints

POST https://alphapen.tech/api/trocr

TrOCR endpoint for text recognition

POST https://alphapen.tech/api/postocr

Post-processing OCR endpoint

POST https://alphapen.tech/api/pipeline

Complete OCR pipeline endpoint

Response Format

text

The extracted text from the image

confidence

Confidence score of the OCR result (0-1)

language

Detected language code

languageConfidence

Confidence score of language detection (0-1)

processingTime

Time taken to process the request in milliseconds