Extract text from a document
OCR recognizes text in PDF, Word, PowerPoint, and image files. Use text recognition for extracted text or rich layout recognition when page layout matters.
Prepare your project
Follow Set up your project and provide ANTAPI_KEY in a trusted terminal or backend. Check availability, response fields, and the published page price in the OCR API reference before calling. A guide can be read before its API Reference is published.
Upload a file
curl "https://api.antapi.dev/ocr/v1/recognize" \
--header "Authorization: Bearer $ANTAPI_KEY" \
--header 'Idempotency-Key: ocr-document-example-001' \
--form purpose=text_recognition \
--form file=@document.pdf
Both purpose and file are required. Use text_recognition for text extraction or rich_layout_recognition for text and layout. Let your HTTP client set the multipart Content-Type and boundary. Files may be up to 100 MiB and 1000 pages; format recognition uses actual file content.
Read the result
Check HTTP status and the JSON code, data, and error envelope. data contains the recognition result and page count. Preserve page boundaries and coordinate markers when using layout results. A length marker indicates truncated text; do not treat that output as a complete transcription of the page.
Build a document reader
Use the recognized text as the starting point for your application's document workflow:
- Upload the document as shown above and save the recognized text. Check for truncation before treating it as a complete document.
- Display the extracted text directly, or pass it to your application or existing model to organize the content into a summary.
- For an audio version, assemble the complete text or summary and follow Text to speech. Let users choose whether to create audio and provide playback in your application.
Your application or agent connects these steps. OCR returns recognition results; it does not automatically summarize or synthesize speech. Each optional TTS call is a separate operation with its own price and saved operation identity. For agent access, configure MCP and approve each tool you intend to use.
Billing and retries
Successful processing is billed by the validated page count, including pages whose text is truncated. A two-page document counts as two pages; token usage is not the billing unit. Authorization uses a maximum of 1000 pages and settlement releases the unused reservation. Failed recognition does not consume billable pages. Admission still depends on your balance, budget, and the platform's shared funding rules; see Balance and billing.
To retry with the same Idempotency-Key, preserve the original encoded multipart bytes and Content-Type boundary. Running the curl command again can generate a different boundary and cause a same-key input conflict. Save the encoded request when exact retries are required. Replays restore execution and financial facts but do not guarantee another copy of the original recognition result. A new key may create another paid recognition.
Save X-Request-ID and inspect usage and receipts after an interruption. A disconnect does not cancel an authorized execution.
Use through MCP
Follow MCP setup, authorize ocr:recognize, and discover ocr_recognize. Inside input, provide purpose and file: {filename: "document.pdf", data_base64: "<Base64 of actual file bytes>"}, with a saved idempotency_key beside input. Use standard, canonically padded Base64; local file paths, file URLs, and object storage URLs are not accepted. The same 100 MiB, 1000-page, and format limits apply. The complete MCP request limit is 134 MiB including Base64 and protocol overhead; clients can impose smaller limits.
Reuse the same file contents, fields, and key for one logical retry. Gateway creates deterministic multipart bytes, so the agent does not manage a boundary. Results contain the public API's JSON data and preserve the original billing and receipts. Availability follows the current release and authorization; existing connections need new consent for the added permission. The existing CLI does not include this operation.