Image OCR
POST /api/image-ocrExtract text from an image (PNG/JPEG): returns the full text, overall confidence (0-100), and per-line bounding boxes. Send POST /api/image-ocr with no required fields (3 optional) and pay $0.01 per call over x402 or MPP (there is no free tier). It returns a JSON object with text, confidence, lang, lineCount, lines and 1 more.
Send either {image: base64} or {url: 'https://…'}. Pure-CPU Tesseract via tesseract.js - no upstream API, no keys. Default lang 'eng'; pass 'lang' (ISO 639-2) for others.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
image | string | no | Base64 PNG/JPEG (data: URL prefix accepted). Either this or url is required. |
url | string | no | HTTPS URL to fetch the image from (max 8 MB). Either this or image is required. |
lang | string | no | Language code, ISO 639-2. Default 'eng'. Supported: eng, spa, fra, deu, ita, por, nld, rus, pol, tur, chi_sim, chi_tra, jpn, kor, ara, hin, tha, vie, ukr, ell. |
Example request
curl -i -X POST https://agent402.tools/api/image-ocr \
-H "Content-Type: application/json" \
-d '{"url":"https://agent402.tools/fixtures/sample-text.png"}'
Without payment this returns HTTP 402 Payment Required with the exact price for image-ocr; any x402 v2 or MPP client pays it and retries.
Example response
{
"text": "Agent402 sample text for OCR.\nInvoice 402-0001 total 12.34 USD.",
"confidence": 94,
"lang": "eng",
"lineCount": 2,
"lines": [
{
"text": "Agent402 sample text for OCR.",
"confidence": 94.34,
"bbox": {
"x0": 24,
"y0": 29,
"x1": 469,
"y1": 60
}
},
{
"text": "Invoice 402-0001 total 12.34 USD.",
"confidence": 96.31,
"bbox": {
"x0": 27,
"y0": 81,
"x1": 514,
"y1": 106
}
}
],
"source": "tesseract.js (Tesseract WASM, Apache-2.0)"
}
| Field | Type | Always present | In the example |
|---|---|---|---|
text | string | yes | Agent402 sample text for OCR. Invoice 402-0001 total 12.34 USD. |
confidence | number | yes | 94 |
lang | string | yes | eng |
lineCount | number | yes | 2 |
lines | array of objects | yes | 2 items in the example |
source | string | yes | tesseract.js (Tesseract WASM, Apache-2.0) |
From an MCP client
catalog.call {
"slug": "image-ocr",
"params": {
"url": "https://agent402.tools/fixtures/sample-text.png"
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for image-ocr; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
- Every field is optional. An input the tool rejects returns an HTTP 4xx whose body carries
error,tool,expected,requiredandexample. - A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - A
GETorHEADto /api/image-ocr returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/image-ocr", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"url": "https://agent402.tools/fixtures/sample-text.png"
}),
});
Part of these workflows
Image OCR is one step in these 3 skill packs, each sold as a single call:
- Content extraction - Turn arbitrary URLs and PDFs into clean structured text - articles, page metadata, PDF pages, OCR'd images, browser-rendered SPAs.
- Document intelligence - Turn any PDF or image URL into structured data - metadata, extracted text, sliced page ranges, OCR for scanned docs, decoded barcodes / QR codes - without falling back to a vision LLM guess. Built for the messy 30% of documents where pdf-to-markdown alone returns nothing useful.
- Convert anything to markdown - Convert anything at a URL - HTML, PDF, or an image - to clean markdown. The 'I have a URL but it might be any content-type, give me markdown either way' workflow: HEAD-detect the content-type, branch to the right deterministic extractor (article extract for HTML, pdf-to-markdown for PDFs, OCR for images), and report token/word stats on the output so the caller can budget the result against an LLM context window.
Related tools
A2A Agent Card validate
POST /api/a2a-card-validateValidate an A2A (Agent2Agent protocol) Agent Card: required fields, skill shape, transport names, capability flags - spe…
Amortization schedule
POST /api/amortizationBuild the full per-period amortization schedule for a fully-amortizing loan. Each row reports the period number, payment…
Annuity present/future value
POST /api/annuityPresent and future value of a level annuity (equal periodic payments). Supports an ordinary annuity (payments at period …
Barcode / QR decode
POST /api/barcode-decodeDecode a barcode or QR code from an image. Send a base64 PNG or JPEG (or a data: URL); returns the decoded text and the …
Barcode product lookup
GET /api/barcode-lookupLook up a product by its UPC/EAN barcode number via Open Food Facts (open data): name, brand, category, quantity, and nu…
Black-Scholes option price
POST /api/black-scholesPrice a European option (call or put) with the Black-Scholes-Merton model, plus the greeks (delta, gamma, vega, theta, r…