Document Processing
8 min reading

How to use Optical Character Recognition (OCR) with JavaScript

Summarize this article with:

summary
  • Optical Character Recognition (OCR) is a technology that converts text from images, scanned documents, or PDFs into machine-readable text.
  • OCR is widely used to digitize printed documents, automate data entry, and extract information from receipts, invoices, contracts, and other documents.
  • Developers can use Optical Character Recognition (OCR) with JavaScript using a REST API that accepts standard inputs and returns structured JSON responses.
  • Simplify development with a single API key that provides access to multiple AI services.
  • OCR is a powerful tool for automating text extraction from documents and images.

In this tutorial, you will learn how to use the OCR API in 5 minutes using JavaScript. Eden AI provides an easy and developer-friendly API that allows you to extract text from images or scanned documents.

What is the OCR API?

Optical Character Recognition (OCR) is a technology that converts text from images, scanned documents, or PDFs into machine-readable text.

OCR is widely used to digitize printed documents, automate data entry, and extract information from receipts, invoices, contracts, and other documents.

Getting Started with OCR

Set Up Your Eden AI Account

1. Sign Up: If you don't have an Eden AI account, create a free here. Once you do that you can obtain your API key, which you can use to access the OCR API.

2. Access the OCR Feature: Once logged in, go to the document section of the platform.

3. Choose the OCR feature: Select the OCR tool. You can also explore other options based on your specific requirements.

How to Implement OCR API using JavaScript?



const axios = require("axios").default;

const options = {
method: "POST",
url: "https://api.edenai.run/v2/ocr/ocr",
headers: {
Authorization: "Bearer YOUR_API_TOKEN", // Replace with your actual API token
},
data: {
providers: ["amazon"], // You can use 'google', 'microsoft', etc.
language: "en", // Language of the text
file_url: "https://your-file-url.com/image.jpg", // Replace with your file URL
},
};

axios
.request(options)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});

Example Output



{
"amazon": {
"status": "success",
"text": "Invoice\nDate: 2026-01-15\nTotal: $1,250.00",
"bounding_boxes": [
{
"text": "Invoice",
"left": 0.1,
"top": 0.05,
"width": 0.2,
"height": 0.04
}
],
"cost": 0.001
}
}

Why Eden AI is the Best for OCR

Eden AI provides several advantages.

Multiple AI Providers

You can choose between different AI services, helping you compare results for the best performance.

Easy Integration

Simplify development with a single API key that provides access to multiple AI services. Eliminate the hassle of managing separate integrations and accelerate your launch.

Cost Efficiency

Only pay for what you use. No upfront costs, just flexible access to multiple AI services with a single API key.

Conclusion

OCR is a powerful tool for automating text extraction from documents and images. Eden AI's OCR API makes it easy to integrate this capability into JavaScript applications with just a few lines of code.

Sign up for free on Eden AI and start extracting text from documents today!

FAQ — use Optical Character Recognition (OCR)

You need an API key from your chosen AI provider. Eden AI lets you access multiple providers with a single key, removing the need for separate vendor accounts.
Any language that supports HTTP requests works — Python, JavaScript, PHP, Ruby, Go, and more. Ready-to-use code snippets are available for the most common languages.
Most developers complete a basic integration in under an hour using standardized API endpoints and ready-to-use code examples.
Implement exponential backoff for rate limit errors and use try-catch blocks for network failures. Eden AI's built-in fallback routing automatically redirects requests if a provider is unavailable.
Eden AI supports GDPR-compliant provider filtering and does not store or reuse your data, ensuring compliance with European privacy regulations.

Similar articles

No items found.
let’s start

Start building with Eden AI

A single interface to integrate the best AI technologies into your products.