Developer Guide

EasyOCR API Integration Guide: From Beginner to Expert

Detailed API integration steps and sample code supporting JavaScript, Python, cURL, and more.

4 min read

Quick Integration Steps

1. Preparation

Ensure your development environment supports HTTP requests and can handle multipart/form-data format.

2. Build the Request

Create a POST request to https://api.easyocr.org/ocr

3. Upload Image

Add the image file to FormData with the field name file

4. Handle Response

Parse the returned JSON data to get the recognition result

5. Error Handling

Implement appropriate error handling logic for potential exceptions

Complete Example

async function recognizeText(imageFile) {
  try {
    const formData = new FormData();
    formData.append('file', imageFile);

    const response = await fetch('https://api.easyocr.org/ocr', {
      method: 'POST',
      body: formData
    });

    if (!response.ok) {
      throw new Error('Recognition failed');
    }

    const data = await response.json();

    // API response format: { words: [{ text, left, top, right, bottom, rate }] }
    if (data.words && Array.isArray(data.words)) {
      // Extract all text content
      const text = data.words.map(word => word.text).join('\\n');
      return { text, words: data.words };
    }

    return data;
  } catch (error) {
    console.error('OCR Error:', error);
    throw error;
  }
}

More Examples

Visit the Quick Start page for sample code in more programming languages.

Was this article helpful?

Visit ourHelp Center

Share: