"""What N pages of OCR cost at each API, from list prices checked on Nov 18, 2026.

Usage:
  python ocr_cost.py 10000            plain text OCR, 10,000 pages a month
  python ocr_cost.py 10000 --tables   table, layout and form prices

Prices change: check each vendor's page before you buy. AWS and Azure are
the US East prices. Left out: free tiers you must sign up for (AWS: 1,000
pages a month for 3 months, new customers; Azure F0: 500 pages a month on a
separate free resource; Apify free plan: 50 pages a month), and tax.
Google lists its first 1,000 pages a month as free, so they are in.
"""

import sys

CHECKED = "2026-11-18"
# Each tier: (from this page of the month, USD per 1,000 pages).
PLAIN = {
    "DeepSeek OCR API": [(0, 0.225)],
    "Mistral OCR 3, Batch API": [(0, 1.00)],
    "Google Vision or Document AI OCR": [(0, 0), (1000, 1.50), (5_000_000, 0.60)],
    "AWS Textract, Detect Document Text": [(0, 1.50), (1_000_000, 0.60)],
    "Azure Document Intelligence, Read": [(0, 1.50), (1_000_000, 0.60)],
    "Mistral OCR 3": [(0, 2.00)],
    "Mistral OCR 4.1": [(0, 4.00)],
    "Brasspage pdf-ocr Actor, scanned pages": [(0, 6.00)],
}
TABLES = {
    "AWS Textract, Layout": [(0, 4.00), (1_000_000, 3.00)],
    "Mistral OCR 4.1, annotated pages": [(0, 5.00)],
    "Brasspage pdf-ocr Actor, Markdown tables": [(0, 6.00)],
    "Azure Document Intelligence, Layout": [(0, 10.00)],
    "Google Document AI, Layout Parser": [(0, 10.00)],
    "AWS Textract, Tables": [(0, 15.00), (1_000_000, 10.00)],
    "Google Document AI, Form Parser": [(0, 30.00), (1_000_000, 20.00)],
    "AWS Textract, Forms": [(0, 50.00), (1_000_000, 40.00)],
}


def cost(tiers, pages):
    total = 0.0
    for i, (start, price) in enumerate(tiers):
        end = tiers[i + 1][0] if i + 1 < len(tiers) else pages
        total += max(0, min(pages, end) - start) * price / 1000
    return total


if __name__ == "__main__":
    if len(sys.argv) < 2 or not sys.argv[1].replace(",", "").isdigit():
        sys.exit(__doc__)
    pages = int(sys.argv[1].replace(",", ""))
    table = TABLES if "--tables" in sys.argv else PLAIN
    print(f"{pages:,} pages a month, list prices checked {CHECKED}")
    for name, tiers in sorted(table.items(), key=lambda kv: cost(kv[1], pages)):
        print(f"{f'${cost(tiers, pages):,.2f}':>11}  {name}")
