DocsRouterDocsRouter
Api

Native OCR Endpoint

DocsRouter native format for document OCR

Native OCR Endpoint

For new integrations, we recommend using the Chat Completions endpoint which is compatible with OpenAI SDKs.

The /v1/ocr endpoint is DocsRouter's native OCR format. It provides a simpler request structure for basic OCR use cases where you just need to extract text from a single image or document.

Endpoint

POST https://api.docsrouter.com/v1/ocr

Authentication

All requests require authentication via the Authorization header:

Authorization: Bearer YOUR_API_KEY

You can obtain an API key from the DocsRouter Dashboard.

Request Headers

HeaderRequiredDescription
AuthorizationYesBearer token: Bearer YOUR_API_KEY
Content-TypeYesMust be application/json

Request Body

The request body should be a JSON object with the following properties:

FieldTypeRequiredDescription
urlstringNo*Publicly accessible URL of the image/document.
base64stringNo*Base64-encoded image data (without data URI prefix).
modelstringNoThe ID of the model to use. Default: google/gemini-2.0-flash-001.
optionsobjectNoAdditional processing options.

* Either url or base64 is required.

Options Object

FieldTypeDefaultDescription
extract_tablesbooleanfalseIf true, attempts to parse tables into structured JSON.
languagestringautoHint for the document language (e.g., "en", "es").
output_formatenumtextPreferred output format: text, json, markdown.

Example Request

curl -X POST https://api.docsrouter.com/v1/ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/invoice.jpg",
    "model": "openai/gpt-4o",
    "options": {
      "extract_tables": true
    }
  }'

Response Body

{
  "id": "req_123...",
  "object": "ocr.result",
  "created": 1716312345,
  "model": "openai/gpt-4o",
  "result": {
    "text": "INVOICE #001...",
    "blocks": [
      { "type": "text", "content": "INVOICE #001" },
      ...
    ],
    "tables": [
      {
        "headers": ["Item", "Price"],
        "rows": [["Widget", "$10.00"]]
      }
    ],
    "confidence": 95,
    "language": "en"
  },
  "usage": {
    "pages_processed": 1,
    "tokens_used": 450,
    "provider_cost_cents": 2,
    "platform_fee_cents": 1,
    "total_cost_cents": 3,
    "processing_time_ms": 1800
  }
}

Response Fields

FieldTypeDescription
idstringUnique request identifier
objectstringAlways ocr.result
creatednumberUnix timestamp of when the request was processed
modelstringThe model that was used
resultobjectThe OCR results
result.textstringFull extracted text
result.blocksarrayText blocks with position information
result.tablesarrayExtracted tables (if extract_tables was true)
result.confidencenumberOverall confidence score (0-100)
result.languagestringDetected language code
usageobjectUsage and cost information

Additional Examples

With Base64 Image

# Encode your image to base64
IMG_BASE64=$(base64 -i document.png | tr -d '\n')

curl -X POST https://api.docsrouter.com/v1/ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "base64": "'"$IMG_BASE64"'",
    "model": "google/gemini-2.0-flash-001"
  }'

With Language Hint

curl -X POST https://api.docsrouter.com/v1/ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/german-invoice.jpg",
    "options": {
      "language": "de",
      "output_format": "markdown"
    }
  }'

JSON Output Format

curl -X POST https://api.docsrouter.com/v1/ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/receipt.jpg",
    "options": {
      "output_format": "json",
      "extract_tables": true
    }
  }'

Error Handling

Status CodeDescription
400Bad Request - Invalid parameters or missing image
401Unauthorized - Invalid or missing API key
402Payment Required - Insufficient credits
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Comparison with Chat Completions

FeatureNative OCR (/v1/ocr)Chat Completions (/v1/chat/completions)
SDK CompatibilityDocsRouter onlyOpenAI, OpenRouter, LangChain, etc.
Request FormatSimple flat structureOpenAI messages format
Multi-image SupportSingle image onlyMultiple images per request
Custom PromptsLimitedFull prompt customization
PDF SupportImages onlyImages and PDFs
StreamingNoYes

For most use cases, we recommend the Chat Completions endpoint for its flexibility and SDK compatibility.

On this page