Extract text from an image (upload, URL or base64)
Extracts the text from an image, line by line (or word by word with positions), with a confidence score.
Request
Upload the image in the file field (max 25 MB). Instead of a file you can send JSON: {"url": "https://…"} for a public image URL, or {"base64": "…"} — the options below then go in the same JSON object.
eng, hin, mar; combine with +, e.g. eng+hin. lines (default) or words (with each word's position and confidence). Parameters and body structure are inherited from this endpoint's definition. Changes here only apply to this test run.
1curl --request POST \
2 --url https://ocr-image-to-text.p.apihiver.com/v1/extract \
3 --header 'Accept: application/json' \
4 --header 'X-API-Key: YOUR_API_KEY' \
5 --header 'content-type: multipart/form-data' \
6 --form file=@file.bin \
7 --form lang=eng \
8 --form layout=linesExtract text from an image (upload, URL or base64): OCR API — Image to Text reference
Extracts the text from an image, line by line (or word by word with positions), with a confidence score. This endpoint is part of the OCR API — Image to Text: Extract text from images and scans in English, Hindi and Marathi, and pull out emails, phone numbers, URLs, PAN and GSTIN.
Extract text from an image (upload, URL or base64): example requests in every language
POST /v1/extract in Shell (cURL)
curl --request POST \
--url https://ocr-image-to-text.p.apihiver.com/v1/extract \
--header 'Accept: application/json' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'content-type: multipart/form-data' \
--form [email protected] \
--form lang=eng \
--form layout=linesPOST /v1/extract in Shell (HTTPie)
echo '-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="lang"
eng
-----011000010111000001101001
Content-Disposition: form-data; name="layout"
lines
-----011000010111000001101001--
' | \
http POST https://ocr-image-to-text.p.apihiver.com/v1/extract \
Accept:application/json \
X-API-Key:YOUR_API_KEY \
content-type:'multipart/form-data; boundary=---011000010111000001101001'POST /v1/extract in Shell (Wget)
wget --quiet \
--method POST \
--header 'Accept: application/json' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file.bin"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="lang"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="layout"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n' \
--output-document \
- https://ocr-image-to-text.p.apihiver.com/v1/extractPOST /v1/extract in Node.js (http)
const http = require('https');
const options = {
method: 'POST',
hostname: 'ocr-image-to-text.p.apihiver.com',
port: null,
path: '/v1/extract',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on('data', function (chunk) {
chunks.push(chunk);
});
res.on('end', function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file.bin"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="lang"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="layout"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n');
req.end();POST /v1/extract in Node.js (Request)
const fs = require('fs');
const request = require('request');
const options = {
method: 'POST',
url: 'https://ocr-image-to-text.p.apihiver.com/v1/extract',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
},
formData: {
file: {
value: fs.createReadStream('file.bin'),
options: {filename: 'file.bin', contentType: 'multipart/form-data'}
},
lang: 'eng',
layout: 'lines'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});POST /v1/extract in Node.js (Unirest)
const fs = require('fs');
const unirest = require('unirest');
const req = unirest('POST', 'https://ocr-image-to-text.p.apihiver.com/v1/extract');
req.headers({
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
});
req.multipart([
{
body: fs.createReadStream('file.bin'),
'content-type': 'multipart/form-data'
},
{
body: 'eng'
},
{
body: 'lines'
}
]);
req.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.body);
});POST /v1/extract in Node.js (Axios)
const axios = require('axios').default;
const options = {
method: 'POST',
url: 'https://ocr-image-to-text.p.apihiver.com/v1/extract',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
},
data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file.bin"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="lang"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="layout"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n'
};
try {
const { data } = await axios.request(options);
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/extract in Node.js (Fetch)
const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');
const formData = new FormData();
formData.append('file', fs.createReadStream('file.bin'));
formData.append('lang', 'eng');
formData.append('layout', 'lines');
const url = 'https://ocr-image-to-text.p.apihiver.com/v1/extract';
const options = {
method: 'POST',
headers: {Accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY'}
};
options.body = formData;
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/extract in JavaScript (XMLHttpRequest)
const data = new FormData();
data.append('file', 'file.bin');
data.append('lang', 'eng');
data.append('layout', 'lines');
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener('readystatechange', function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open('POST', 'https://ocr-image-to-text.p.apihiver.com/v1/extract');
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('X-API-Key', 'YOUR_API_KEY');
xhr.send(data);POST /v1/extract in JavaScript (Axios)
import axios from 'axios';
const form = new FormData();
form.append('file', 'file.bin');
form.append('lang', 'eng');
form.append('layout', 'lines');
const options = {
method: 'POST',
url: 'https://ocr-image-to-text.p.apihiver.com/v1/extract',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY',
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
},
data: '[form]'
};
try {
const { data } = await axios.request(options);
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/extract in JavaScript (Fetch)
const url = 'https://ocr-image-to-text.p.apihiver.com/v1/extract';
const form = new FormData();
form.append('file', 'file.bin');
form.append('lang', 'eng');
form.append('layout', 'lines');
const options = {
method: 'POST',
headers: {Accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY'}
};
options.body = form;
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}POST /v1/extract in JavaScript (jQuery)
const form = new FormData();
form.append('file', 'file.bin');
form.append('lang', 'eng');
form.append('layout', 'lines');
const settings = {
async: true,
crossDomain: true,
url: 'https://ocr-image-to-text.p.apihiver.com/v1/extract',
method: 'POST',
headers: {
Accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
processData: false,
contentType: false,
mimeType: 'multipart/form-data',
data: form
};
$.ajax(settings).done(function (response) {
console.log(response);
});POST /v1/extract in Python (http.client)
import http.client
conn = http.client.HTTPSConnection("ocr-image-to-text.p.apihiver.com")
payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n"
headers = {
'Accept': "application/json",
'X-API-Key': "YOUR_API_KEY",
'content-type': "multipart/form-data; boundary=---011000010111000001101001"
}
conn.request("POST", "/v1/extract", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))POST /v1/extract in Python (Requests)
import requests
url = "https://ocr-image-to-text.p.apihiver.com/v1/extract"
files = { "file": "open('file.bin', 'rb')" }
payload = {
"lang": "eng",
"layout": "lines"
}
headers = {
"Accept": "application/json",
"X-API-Key": "YOUR_API_KEY"
}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.json())POST /v1/extract in PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://ocr-image-to-text.p.apihiver.com/v1/extract",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n",
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"X-API-Key: YOUR_API_KEY",
"content-type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}POST /v1/extract in PHP (Guzzle)
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://ocr-image-to-text.p.apihiver.com/v1/extract', [
'multipart' => [
[
'name' => 'file',
'filename' => 'file.bin',
'contents' => null,
'headers' => [
'Content-Type' => 'multipart/form-data'
]
],
[
'name' => 'lang',
'contents' => 'eng'
],
[
'name' => 'layout',
'contents' => 'lines'
]
]
'headers' => [
'Accept' => 'application/json',
'X-API-Key' => 'YOUR_API_KEY',
],
]);
echo $response->getBody();POST /v1/extract in PHP (PECL HTTP v1)
<?php
$request = new HttpRequest();
$request->setUrl('https://ocr-image-to-text.p.apihiver.com/v1/extract');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders([
'Accept' => 'application/json',
'X-API-Key' => 'YOUR_API_KEY',
'content-type' => 'multipart/form-data; boundary=---011000010111000001101001'
]);
$request->setBody('-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="lang"
eng
-----011000010111000001101001
Content-Disposition: form-data; name="layout"
lines
-----011000010111000001101001--
');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}POST /v1/extract in PHP (PECL HTTP v2)
<?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->addForm([
'lang' => 'eng',
'layout' => 'lines'
], [
[
'name' => 'file',
'type' => 'multipart/form-data',
'file' => 'file.bin',
'data' => null
]
]);
$request->setRequestUrl('https://ocr-image-to-text.p.apihiver.com/v1/extract');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'Accept' => 'application/json',
'X-API-Key' => 'YOUR_API_KEY'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();POST /v1/extract in Java (AsyncHttp)
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("POST", "https://ocr-image-to-text.p.apihiver.com/v1/extract")
.setHeader("Accept", "application/json")
.setHeader("X-API-Key", "YOUR_API_KEY")
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();
client.close();POST /v1/extract in Java (java.net.http)
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ocr-image-to-text.p.apihiver.com/v1/extract"))
.header("Accept", "application/json")
.header("X-API-Key", "YOUR_API_KEY")
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());POST /v1/extract in Java (OkHttp)
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n");
Request request = new Request.Builder()
.url("https://ocr-image-to-text.p.apihiver.com/v1/extract")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("X-API-Key", "YOUR_API_KEY")
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.build();
Response response = client.newCall(request).execute();POST /v1/extract in Java (Unirest)
HttpResponse<String> response = Unirest.post("https://ocr-image-to-text.p.apihiver.com/v1/extract")
.header("Accept", "application/json")
.header("X-API-Key", "YOUR_API_KEY")
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n")
.asString();POST /v1/extract in C# (HttpClient)
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://ocr-image-to-text.p.apihiver.com/v1/extract"),
Headers =
{
{ "Accept", "application/json" },
{ "X-API-Key", "YOUR_API_KEY" },
},
Content = new MultipartFormDataContent
{
new StringContent("")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("multipart/form-data"),
ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = "file.bin",
}
}
},
new StringContent("eng")
{
Headers =
{
ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "lang",
}
}
},
new StringContent("lines")
{
Headers =
{
ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "layout",
}
}
},
},
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}POST /v1/extract in C# (RestSharp)
var client = new RestClient("https://ocr-image-to-text.p.apihiver.com/v1/extract");
var request = new RestRequest("", Method.Post);
request.AddHeader("Accept", "application/json");
request.AddHeader("X-API-Key", "YOUR_API_KEY");
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
var response = client.Execute(request);POST /v1/extract in Go (NewRequest)
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://ocr-image-to-text.p.apihiver.com/v1/extract"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("X-API-Key", "YOUR_API_KEY")
req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}POST /v1/extract in Ruby (net::http)
require 'uri'
require 'net/http'
url = URI("https://ocr-image-to-text.p.apihiver.com/v1/extract")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = 'application/json'
request["X-API-Key"] = 'YOUR_API_KEY'
request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n"
response = http.request(request)
puts response.read_bodyPOST /v1/extract in Swift (NSURLSession)
import Foundation
let headers = [
"Accept": "application/json",
"X-API-Key": "YOUR_API_KEY",
"content-type": "multipart/form-data; boundary=---011000010111000001101001"
]
let parameters = [
[
"name": "file",
"fileName": "file.bin",
"contentType": "multipart/form-data"
],
[
"name": "lang",
"value": "eng"
],
[
"name": "layout",
"value": "lines"
]
]
let boundary = "---011000010111000001101001"
var body = ""
var error: NSError? = nil
for param in parameters {
let paramName = param["name"]!
body += "--\(boundary)\r\n"
body += "Content-Disposition:form-data; name=\"\(paramName)\""
if let filename = param["fileName"] {
let contentType = param["content-type"]!
let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
if (error != nil) {
print(error as Any)
}
body += "; filename=\"\(filename)\"\r\n"
body += "Content-Type: \(contentType)\r\n\r\n"
body += fileContent
} else if let paramValue = param["value"] {
body += "\r\n\r\n\(paramValue)"
}
}
let request = NSMutableURLRequest(url: NSURL(string: "https://ocr-image-to-text.p.apihiver.com/v1/extract")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error as Any)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()POST /v1/extract in Objective-C (NSURLSession)
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"Accept": @"application/json",
@"X-API-Key": @"YOUR_API_KEY",
@"content-type": @"multipart/form-data; boundary=---011000010111000001101001" };
NSArray *parameters = @[ @{ @"name": @"file", @"fileName": @"file.bin", @"contentType": @"multipart/form-data" },
@{ @"name": @"lang", @"value": @"eng" },
@{ @"name": @"layout", @"value": @"lines" } ];
NSString *boundary = @"---011000010111000001101001";
NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
if (param[@"fileName"]) {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
[body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
if (error) {
NSLog(@"%@", error);
}
} else {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://ocr-image-to-text.p.apihiver.com/v1/extract"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];POST /v1/extract in Kotlin (OkHttp)
val client = OkHttpClient()
val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001")
val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n")
val request = Request.Builder()
.url("https://ocr-image-to-text.p.apihiver.com/v1/extract")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("X-API-Key", "YOUR_API_KEY")
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.build()
val response = client.newCall(request).execute()POST /v1/extract in C (libcurl)
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://ocr-image-to-text.p.apihiver.com/v1/extract");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "X-API-Key: YOUR_API_KEY");
headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n");
CURLcode ret = curl_easy_perform(hnd);POST /v1/extract in Clojure (clj-http)
(require '[clj-http.client :as client])
(client/post "https://ocr-image-to-text.p.apihiver.com/v1/extract" {:headers {:X-API-Key "YOUR_API_KEY"}
:multipart [{:name "file"
:content (clojure.java.io/file "file.bin")} {:name "lang"
:content "eng"} {:name "layout"
:content "lines"}]
:accept :json})POST /v1/extract in OCaml (CoHTTP)
open Cohttp_lwt_unix
open Cohttp
open Lwt
let uri = Uri.of_string "https://ocr-image-to-text.p.apihiver.com/v1/extract" in
let headers = Header.add_list (Header.init ()) [
("Accept", "application/json");
("X-API-Key", "YOUR_API_KEY");
("content-type", "multipart/form-data; boundary=---011000010111000001101001");
] in
let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n" in
Client.call ~headers ~body `POST uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)POST /v1/extract in R (httr)
library(httr)
url <- "https://ocr-image-to-text.p.apihiver.com/v1/extract"
payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.bin\"\r\nContent-Type: multipart/form-data\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lang\"\r\n\r\neng\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"layout\"\r\n\r\nlines\r\n-----011000010111000001101001--\r\n"
encode <- "multipart"
response <- VERB("POST", url, body = payload, add_headers('X-API-Key' = 'YOUR_API_KEY'), content_type("multipart/form-data"), accept("application/json"), encode = encode)
content(response, "text")POST /v1/extract in PowerShell (Invoke-WebRequest)
$headers=@{}
$headers.Add("Accept", "application/json")
$headers.Add("X-API-Key", "YOUR_API_KEY")
$headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
$response = Invoke-WebRequest -Uri 'https://ocr-image-to-text.p.apihiver.com/v1/extract' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="lang"
eng
-----011000010111000001101001
Content-Disposition: form-data; name="layout"
lines
-----011000010111000001101001--
'POST /v1/extract in PowerShell (Invoke-RestMethod)
$headers=@{}
$headers.Add("Accept", "application/json")
$headers.Add("X-API-Key", "YOUR_API_KEY")
$headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
$response = Invoke-RestMethod -Uri 'https://ocr-image-to-text.p.apihiver.com/v1/extract' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="lang"
eng
-----011000010111000001101001
Content-Disposition: form-data; name="layout"
lines
-----011000010111000001101001--
'POST /v1/extract in HTTP (HTTP/1.1)
POST /v1/extract HTTP/1.1
Accept: application/json
X-Api-Key: YOUR_API_KEY
Content-Type: multipart/form-data; boundary=---011000010111000001101001
Host: ocr-image-to-text.p.apihiver.com
Content-Length: 339
-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="file.bin"
Content-Type: multipart/form-data
-----011000010111000001101001
Content-Disposition: form-data; name="lang"
eng
-----011000010111000001101001
Content-Disposition: form-data; name="layout"
lines
-----011000010111000001101001--
Example response (200, application/json)
Success.
1{
2 "text": "Invoice from APIHiver\nEmail: [email protected]\n\nPhone: +91 98765 43210",
3 "image": {
4 "width": 900,
5 "height": 300
6 },
7 "language": "eng",
8 "word_count": 9,
9 "average_confidence": 92.4
10}Errors
- 400 — A required parameter is missing or a value has the wrong format.
1{ 2 "error": { 3 "code": "INVALID_INPUT", 4 "message": "Provide a file upload, 'url', or 'base64'." 5 } 6}
Gateway errors (missing key, no subscription, rate limits) are listed in Error codes.
Other OCR API — Image to Text endpoints
- GETOCR languages installed on this server
- POSTRead an image and pull out emails, phone numbers, URLs, dates, amounts, PAN and GSTIN
- POSTDetect page rotation and script (e.g. a scan that's upside down)
OCR API — Image to Text pricing →·OCR API — Image to Text overview →