OCR API

POST /api/v1/ocr/extract extracts text from images and documents as Markdown.

Extract text from an image or document as Markdown, using Cloudflare Workers AI's document-to-markdown conversion.

Send an LLM API key (sk-ar-v1-…) from /dashboard/keys as Authorization: Bearer …. Management keys (ak_…) are not accepted.

Request

Send a JSON body with a base64 image, or a multipart file upload.

FieldTypeRequiredDescription
imagestringyes (JSON only)Base64-encoded image bytes, or a data URL (data:<mime>;base64,<data>).
filenamestringno (JSON only)Filename hint for file-type detection. Defaults to image.png when not set.

For multipart/form-data, include the file in a field named image. The filename is taken from the Content-Disposition header.

Supported formats

Any format Workers AI toMarkdown supports, including PNG, JPEG, GIF, WebP, BMP, TIFF, and PDF.

Maximum file size is 5 MiB; larger requests get 413.

Response

{
  "text": "# Invoice #1042\n\n**Date:** 2026-06-15  \n**Amount:** $120.00\n\n## Line items\n\n| Description | Price |\n|---|---|\n| API credits | $120.00 |",
  "format": "markdown",
  "model": "cloudflare/ai-to-markdown",
  "tokens": 68
}
FieldTypeDescription
textstringExtracted content in Markdown format.
formatstringAlways "markdown".
modelstringAlways "cloudflare/ai-to-markdown".
tokensnumberToken count consumed by the extraction.

Examples

# JSON — base64 data URL
curl https://anyrouter.dev/api/v1/ocr/extract \
  -H "Authorization: Bearer $ANYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"image\": \"$(base64 -i receipt.png | tr -d '\n')\"}"

# Multipart — raw file upload
curl https://anyrouter.dev/api/v1/ocr/extract \
  -H "Authorization: Bearer $ANYROUTER_API_KEY" \
  -F "image=@receipt.png"

Errors

StatusCodeDescription
400missing_required_fieldsThe image field is absent or empty.
400invalid_request_bodyThe request body is not valid JSON or is not parseable multipart.
400invalid_image_encodingThe image value is not valid base64 or a valid data URL.
400invalid_image_fieldThe multipart image field is a string, not a file.
401invalid_api_keyThe API key is missing, expired, or invalid.
413image_too_largeThe image exceeds the 5 MiB limit.
500missing_workers_ai_bindingThe Workers AI binding is not configured (server misconfiguration).
502ocr_upstream_failedThe extraction call failed. Retry the request.
502ocr_extraction_errorWorkers AI returned an error for this file (for example: unsupported format or corrupt data).

See Errors for retry guidance.

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer