orq.aiAdvent of RoutingDocs

Door 5 · still sealed

Hands off the wax, elf. This door opens on Dec 5.

-days--hours--min--sec

Rudolph is still polishing this one. Back to the calendar

Door 5 · Dec 5 OCR & multimodal

Reading handwritten letters

Turn a scanned letter into markdown, page by page, or ask a vision model what the child drew. Same base URL, same API key.

The post room is ankle-deep in letters, half of them in crayon. The toy list is due at the workshop by morning, and Sprocket has already uncapped a pen.

  1. Sprocket

    Not one of these is typed! Fine. I'll type them all up myself by morning. How hard can crayon be?

  2. Mrs. Claus

    Before anything leaves this room: who can see these letters? They carry children's names and home addresses.

  3. Tinsel

    Whoever runs the model reads every page we send. So send the letter, not the envelope.

  4. Sprocket

    And this one is just a crayon pony with an arrow. The arrow says THIS ONE. Underlined three times.

  5. Tinsel

    Two desks, one key. Scans go to /ocr and come back as markdown per page, and drawings go to a vision model as an image.

clientYour appletter.pdf · drawing.pngorq.aiAI Router/ocr · /chat/completionsocrMistral OCR 4.1mistral-ocr-4-1visionClaude Sonnet 5.5claude-sonnet-5-5textMarkdown per pagepages[].markdownanswerWhat was drawnmessage.contentdocumentimage
  1. clientYour appletter.pdf · drawing.png
  2. orq.aiAI Router/ocr · /chat/completions
  3. ocrMistral OCR 4.1mistral-ocr-4-1
    visionClaude Sonnet 5.5claude-sonnet-5-5
  4. textMarkdown per pagepages[].markdown
    answerWhat was drawnmessage.content
Two desks behind one router: the scan goes to the OCR model and comes back as markdown page by page, and the crayon pony goes to a vision model that says what it is.

How it works

Tinsel’s two desks share one base URL and one API key. Pick the desk by what you want back.

  1. OCR endpoint. POST /v3/router/ocr with a model and a document. The document is either a document_url (for example a PDF) or an image_url.
  2. Pages and images. pages is a list of 0-based page indices. Omit it, or pass null, for all pages. ocr_settings controls how extracted images come back: include_image_base64 returns them inline as base64, and max_images_to_include and image_min_size limit which ones are included.
  3. Markdown back. The response has the model, a pages array where each page carries its index, markdown and images, and a usage object counting pages or tokens.
  4. Vision instead. To ask a question about the letter, put the image or PDF in the message content next to your text, on /v3/router/responses or /v3/router/chat/completions. The router converts it to the shape the provider expects.

Try it with curl

This sends the sample PDF from the docs. Swap in the URL of your own scan.

PDF="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf"

curl -s -X POST https://my.orq.ai/v3/router/ocr \
  -H "Authorization: Bearer $ORQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF | jq -r '.pages[].markdown'
{
  "model": "mistral/mistral-ocr-4-1",
  "document": {
    "type": "document_url",
    "document_url": "$PDF/dummy.pdf",
    "document_name": "letter-to-santa.pdf"
  },
  "pages": [0]
}
EOF

Or from the OpenAI SDK

For the drawing, send the image as a base64 data URI in a Chat Completions image_url part:

import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ORQ_API_KEY"],
    base_url="https://my.orq.ai/v3/router",
)

with open("drawing.png", "rb") as f:
    b64 = base64.b64encode(f.read()).decode("utf-8")

response = client.chat.completions.create(
    model="anthropic/claude-sonnet-5-5",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text",
             "text": "List every toy drawn on this letter."},
            {"type": "image_url",
             "image_url": {
                 "url": f"data:image/png;base64,{b64}",
                 "detail": "high",
             }},
        ],
    }],
)
print(response.choices[0].message.content)

detail takes low (512x512), high (full resolution) or auto, the default.

OCR or vision?

You want Send it to
The text, page by page, as markdown /v3/router/ocr
An answer about a drawing or a form An image or file part on a chat model
Both, from a messy scan OCR first, then the markdown to a chat model

The content part names differ per API:

Image Document
Responses API input_image input_file
Chat Completions image_url file

Which models read what

Image support and PDF support are separate. In the model catalog, anthropic/claude-sonnet-5-5 and google/gemini-4-neon list both image and PDF input. openai/gpt-6.2-sol lists image only.

A part a provider cannot accept may be dropped rather than rejected. The request succeeds and the model answers without seeing the file. On Chat Completions, OpenAI and OpenAI-compatible providers return 400 instead when the file is in the latest user message.

Limits and privacy

Each image can be up to 20MB, as JPEG, PNG, WebP or static GIF. Some models accept only one image per prompt. The provider that runs the model receives every page you send, so leave out what it does not need to read.

Nice list

  • Check that a model reads PDFs before you send one. Image support and PDF support are separate capabilities.
  • Default to a base64 data URI in a content part. The docs call it the safest choice: it works with every provider.
  • Ask only for the pages you need with pages. Indices start at 0, so the first page is [0].

Naughty list

  • Sending a PDF to a model that only reads images. The part may be dropped, the request still succeeds, and the model answers about a letter it never saw.
  • Sending a document file_url to an OpenAI model. It does not reach OpenAI. Send base64 file_data or an Orq.ai file_id instead.
  • Leaving out filename on a document sent as file_data. It is required there, unlike for images; only an uploaded file_id can skip it.
  • Adding your own fields to the OCR request body. Its schema does not allow unknown properties.

Elf's challenge

Did the post room bill Santa by the page or by the token? OCR only the first page of the docs' sample PDF, print the raw JSON, and read the page's index and the usage.type.

Stuck? Ask Tinsel for a hint

The page comes back with index 0, because page numbers start from 0. The usage object says what was counted: its type is pages with pages_processed, or tokens with tokens_processed.

Christmas crackerWhat carol does the OCR model sing while it types up Santa's post?Pull it for the punchline

"Markdown the halls", one page at a time.