API Reference

OCR API Reference

Complete reference for the OCR endpoint — request parameters, response schema, code examples, and supported options.

Endpoint

POST /api/v1/ocr

Scope required: ocr

Request

Headers

HeaderRequiredDescription
Authorization: Bearer <key>Yes*API key with ocr scope
x-api-key: <key>Yes*Alternative to Bearer token
Idempotency-KeyNoSafe retry key (max 191 chars, alphanumeric + ._:-)
Content-TypeYesmultipart/form-data or application/json

*Exactly one authentication header required.

Input Source (choose one)

FieldTypeSource
fileBinaryFile upload via multipart
image_urlString (URI)Public HTTP/HTTPS URL
base64StringBase64-encoded file content

When using base64, also provide mime_type (e.g., image/png, application/pdf).

Mode

FieldTypeDefaultValues
modeStringformattedsimple, formatted
  • simple — plain text output (lower cost, 1 credit/page)
  • formatted — Markdown with headings, tables, lists, code blocks preserved (10 credits/page)

Multipart Example

curl -X POST https://image-to-text.org/api/v1/ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "[email protected]" \
  -F "mode=formatted"

JSON Example

curl -X POST https://image-to-text.org/api/v1/ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image_url": "https://example.com/page.png", "mode": "simple"}'

Response

Success (200)

{
  "success": true,
  "request_id": "req_abc123...",
  "elapsed_ms": 2340,
  "data": {
    "markdown": "# Invoice\n\n| Item | Qty | Price |\n|------|-----|-------|\n...",
    "text": "Invoice\nItem Qty Price\n...",
    "pages": [
      {
        "pageNumber": 1,
        "markdown": "# Invoice\n\n...",
        "text": "Invoice\n...",
        "blocks": [
          {
            "type": "heading",
            "markdown": "# Invoice",
            "bbox": [72, 100, 540, 130],
            "confidence": 0.98
          },
          {
            "type": "table",
            "markdown": "| Item | Qty | Price |\n|------|-----|-------|",
            "bbox": [72, 200, 540, 400],
            "confidence": 0.95
          }
        ]
      }
    ],
    "usage": {
      "credits": 10,
      "pages": 1,
      "mode": "formatted"
    }
  }
}

Response Fields

FieldTypeDescription
successBooleanAlways true for successful requests
request_idStringUnique identifier for this request
elapsed_msIntegerProcessing time in milliseconds
data.markdownStringFull document Markdown (all pages concatenated)
data.textStringPlain text version of the document
data.pagesArrayPer-page results (see below)
data.usageObjectBilling summary

Page Object

FieldTypeDescription
pageNumberInteger1-based page index
markdownStringPage Markdown content
textStringPage plain text
blocksArrayRecognized text blocks

Block Object

FieldTypeDescription
typeStringheading, paragraph, list, table, code
markdownStringBlock content in Markdown
bbox[Number][x1, y1, x2, y2] bounding box coordinates
confidenceNumberRecognition confidence (0–1)

Error Responses

All errors follow the standard error contract.

{
  "success": false,
  "request_id": "req_abc123...",
  "error": {
    "code": "empty_result",
    "message": "No readable text was found in this file.",
    "retryable": false
  }
}

Limits

LimitValue
Max file size20 MB
Max pages per requestConfigurable (default ~50)
Supported image formatsJPEG, PNG, GIF, WebP, BMP, TIFF
Supported document formatPDF

Code Examples

Python

import requests

response = requests.post(
    "https://image-to-text.org/api/v1/ocr",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Idempotency-Key": "ocr-2024-001",
    },
    json={
        "image_url": "https://example.com/document.png",
        "mode": "formatted",
    },
)

data = response.json()
if data["success"]:
    print(data["data"]["markdown"])
else:
    print(f"Error: {data['error']['message']}")

Node.js

const response = await fetch("https://image-to-text.org/api/v1/ocr", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    image_url: "https://example.com/document.png",
    mode: "formatted",
  }),
});

const data = await response.json();
if (data.success) {
  console.log(data.data.markdown);
}