Docs📄 DocumentsOCR — Text from Images
POST/api/ocr$0.02

📄 OCR — Text from Images

Extract all visible text from any image using Claude's vision capabilities. Handles printed text, handwriting, receipts, invoices, screenshots, and documents. Supports JPEG, PNG, GIF, and WebP. Input can be an image URL or base64-encoded data. Returns extracted text, detected language, and confidence score.

Request Body

ParameterTypeRequiredDescriptionDefault
imagestringrequiredPublic image URL (https://) OR base64-encoded image (with or without data URI prefix)
languagestringoptionalISO 639-1 language hint (e.g. en, fr, ja) or 'auto' to detectauto

Response Fields

FieldTypeDescription
textstringAll text extracted from the image (empty string if none found)
languagestringDetected or confirmed ISO 639-1 language code
confidencenumberExtraction confidence score 0.0–1.0
sourcestringInput type used: url | base64
processedAtstringISO 8601 timestamp of when OCR was performed

Code Examples

cURL
bash
# From URL
curl -X POST https://sparkforge.sh/api/ocr \
  -H "Content-Type: application/json" \
  -H "X-PAYMENT: <x402-payment-token>" \
  -d '{
    "image": "https://example.com/invoice.jpg",
    "language": "en"
  }'

# From base64
curl -X POST https://sparkforge.sh/api/ocr \
  -H "Content-Type: application/json" \
  -H "X-PAYMENT: <x402-payment-token>" \
  -d '{"image": "data:image/png;base64,iVBORw0KGgo..."}'
Python
python
import requests, base64

# From URL
response = requests.post(
    "https://sparkforge.sh/api/ocr",
    headers={"Content-Type": "application/json", "X-PAYMENT": "<token>"},
    json={"image": "https://example.com/receipt.jpg", "language": "en"}
)

# From file
with open("receipt.jpg", "rb") as f:
    b64 = base64.b64encode(f.read()).decode()

response = requests.post(
    "https://sparkforge.sh/api/ocr",
    headers={"Content-Type": "application/json", "X-PAYMENT": "<token>"},
    json={"image": b64}
)

data = response.json()
print(data["text"])
print(f"Language: {data['language']} | Confidence: {data['confidence']:.0%}")
TypeScript / Node.js
typescript
import * as fs from "fs";

// From URL
const res = await fetch402("https://sparkforge.sh/api/ocr", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ image: "https://example.com/receipt.jpg" }),
});

const { text, language, confidence } = await res.json();
console.log(`Extracted (${language}, ${(confidence * 100).toFixed(0)}% confidence):`, text);

Example Response

json
{
  "text": "Invoice #4821\nDate: 2024-03-01\nBill To: Acme Corp\n\nItem           Qty  Price\nWidget Pro      2    $25.00\nShipping               $5.00\n\nTotal Due: $55.00",
  "language": "en",
  "confidence": 0.97,
  "source": "url",
  "processedAt": "2026-02-28T16:00:00.000Z"
}

💳 Payment via x402

This endpoint costs $0.02 per call, paid in USDC on Base, Polygon, or Solana. Use the @x402/fetch library to handle payments automatically, or implement the x402 handshake manually.

bash
# Free demo mode (no payment)
curl https://sparkforge.sh/api/ocr?demo=true

# Or try via MCP (Claude Desktop, Cursor, Windsurf)
# Add to mcp config: { "url": "https://sparkforge.sh/api/mcp" }
Previous
File Format Converter
Next
Site Crawler