API Reference

Integrate schema-validated OCR into your application.

Authentication

Authenticate your API requests by including your secret API key in the x-api-key header. You can generate and manage your API keys in the developer dashboard.

x-api-key: ocr-tok_...123abc

Extract Custom Schema

Post/v1/extract

Upload a document (PDF or Image) and a JSON schema. The API will route the document to the optimal engine and return a strictly typed JSON object matching your schema.

Request Parameters (multipart/form-data)

fileRequired
binary (PDF, PNG, JPEG)

The document file to be parsed. Max size 5MB.

schemaRequired
string (JSON)

A stringified JSON object defining the exact keys and types you want extracted.

MCP Server (Claude, Cursor & AI Agents)

Streamable HTTP
MCP Endpointhttps://api.smartocr.dev/mcpSmart OCR MCP connector

Connect Smart OCR directly to Claude Desktop, Cursor, Windsurf, Cline, or any Model Context Protocol (MCP) client over Streamable HTTP (2025-03-26). Pass your x-api-key header in your MCP client configuration to give your AI agents instant access to custom JSON schema extraction and table parsing.

1-Command Auto-Install & CLI (npm)

# Auto-configure Cursor, Claude Desktop, Antigravity & Windsurf
npx -y smartocr-mcp install

# Or extract any local PDF/image directly from the terminal
npx -y smartocr-mcp extract ./invoice.pdf

MCP Client Configuration (mcp.json)

{
  "mcpServers": {
    "smartocr": {
      "url": "https://api.smartocr.dev/mcp",
      "headers": {
        "x-api-key": "ocr-tok_...123abc"
      }
    }
  }
}

Exposed MCP Tools

extract_document_jsonCustom Schema

Extracts strict, type-safe JSON matching any custom schema object from a file_url or file_base64 (PDF, PNG, JPG, WEBP, TIFF). Works on the free tier (2/day) or deducts 1 credit/page with an API key.

extract_document_tableTable / CSV / Markdown

Extracts flat 2D spreadsheet rows and columns as a Markdown table and RFC-4180 CSV from invoices, bank statements, receipts, and scanned PDF tables.

extract_document_textPlain Text OCR

Extracts verbatim plain-text OCR transcription across Native PDF, Google Cloud Vision, and AWS Textract without LLM rewriting.

extract_document_batchBatch (2–5 Docs)

Extracts structured JSON matching one shared schema across 2 to 5 document URLs in a single batch call.

submit_document_job / get_document_jobAsync & Webhooks

Creates a tracked asynchronous extraction job (jobId) with optional HTTP webhook delivery and retrieves status/results by job_id.

get_smartocr_statusRead-Only

Checks your remaining Smart OCR API credit balance or daily free-tier status.

Async Extraction & Webhooks

Post/v1/extract-async

Submit large documents for asynchronous processing to prevent HTTP timeouts. Returns a jobId immediately. Once processing completes, the result is sent via POST to your configured Webhook URL.

Request Parameters

This endpoint accepts the same file and schema parameters as the standard extract endpoint, plus one additional optional parameter:

webhookUrlOptional
string (URL)

The URL where the final extracted JSON should be sent. If no default exists and this is omitted, the request returns a 400 Bad Request.

Dashboard Configuration

You do not need to send the webhook URL in every API request. You can easily set, edit, or remove your default Webhook URL at any time directly from the API Keys section in your SmartOCR dashboard. If a default is set on your dashboard API key, the API will automatically use it whenever you omit the webhookUrl parameter in your request body.

Initial Response (200 OK)

{
  "jobId": "uuid-string",
  "status": "PROCESSING",
  "message": "Document is processing in the background. Webhook will be sent upon completion."
}

The Webhook Payload

Our servers will fire a POST request to your resolved webhook URL when processing concludes.

Successful Processing
{
  "jobId": "uuid-string",
  "status": "COMPLETED",
  "data": {
    "extractedData": { ... }, 
    "confidenceScore": 95,
    "processedAt": "2026-06-29T12:00:00.000Z",
    "creditsRemaining": 98
  }
}
Failed Processing
{
  "jobId": "uuid-string",
  "status": "FAILED",
  "error": "Reason for failure (e.g., Timeout, Unreadable document)"
}

Fallback Polling Endpoint

Get/v1/job/:id

If your webhook server drops the payload or you prefer to poll manually, you can fetch the job status. Requires the x-api-key header.

{
  "jobId": "uuid-string",
  "status": "PROCESSING | COMPLETED | FAILED",
  "result": { ... },
  "createdAt": "2026-06-29T12:00:00.000Z",
  "completedAt": "2026-06-29T12:05:00.000Z"
}

File Integrity & Safety

To guarantee secure and reliable processing, the SmartOCR API performs strict real-time validation on all uploaded files before sending them to the inference engines.

Magic Byte Signature Verification

To prevent extension-spoofing attacks (e.g. renaming an executable to a .pdf), we verify file headers at the binary level. If the magic bytes do not match the declared MIME type, the request will fail with:

"Invalid [format] file signature. The file may be corrupted or renamed."

PDF Structural Integrity Check

All PDF uploads undergo deep structural analysis. If a PDF is corrupted, lacks a catalog, or has parsing anomalies, the API returns:

"Corrupted or invalid PDF file structure."

Encryption Detection

Password-protected, encrypted, or DRM-locked PDF documents cannot be processed. These will be rejected immediately with:

"Password protected PDFs are not supported."

Status Codes

SmartOCR uses standard HTTP response codes to indicate the success or failure of an API request.

  • 200
    OK
    Successful extraction.
  • 400
    Bad Request
    Invalid schema format, missing file, corrupted structures, spoofed file signatures, or password-protected PDFs.
  • 401
    Unauthorized
    API key is missing, invalid, or inactive.
  • 402
    Payment Required
    Out of credits. Top up required.
  • 429
    Too Many Requests
    Rate limit exceeded (10 req/min for free, 100 for premium).
  • 500
    Server Error
    All fallback providers failed to process the document.
curl -X POST https://api.smartocr.dev/v1/extract \
  -H "x-api-key: ocr-tok_...123abc" \
  -F "file=@/path/to/invoice.pdf" \
  -F 'schema={"invoiceNumber": "string", "totalDue": "number"}'
Response200 OK
{
  "extractedData": {
    "invoiceNumber": "INV-2847",
    "totalDue": 9782.00
  },
  "confidenceScore": 95,
  "processedAt": "2026-05-31T18:00:00.000Z",
  "creditsRemaining": 499
}