Document Endpoints

The document tools read scanned PDFs and photos of documents. They are part of All tools:

  • documents.ocr returns the text of each page, as plain text and as Markdown.
  • documents.tables returns every table with its rows, plus a CSV file.
  • documents.fields returns the fields you ask for, such as the total of an invoice, with the pages they came from.

They read PDF, PNG, JPEG, WebP, TIFF and HEIC files. For Word, Excel, PowerPoint, e-books and PDFs that already have text, convert.file is faster. The document tools also work on those PDFs when you need their tables or fields, or when their text layer is broken.

A start needs the scope and enough credits, and the tool must be available in /v1/health. Free credits also follow the free limits. Accepted starts return 202 Accepted; poll their status.

All document endpoints are preview. Preview means the contract may still evolve before stable release.

Shared Access

  • Access: Paid plans that include this family, or free credits (guest trial or verified account) within the free limits.
  • Operation family: Documents
  • Scope: api:convert:write, the same scope as file conversion
  • Idempotency: Idempotency-Key header required

Sources

Every request has a source:

{ "source": { "type": "url", "url": "https://upload.wikimedia.org/wikipedia/commons/b/bf/Einstein-Roosevelt-letter.png" } }
  • {"type": "file_id", "id": "fil_..."}: a file you uploaded with POST /v1/files or the hosted MCP upload link. Wait until the file is available.
  • {"type": "artifact_id", "id": "art_..."}: an artifact of an earlier operation, such as a screenshot from screenshots.url.
  • {"type": "url", "url": "https://..."}: a public https URL. Chab downloads the file when the operation runs, with the same address checks as the scrape tools, and checks it for viruses like an upload. The download may be as large as your plan's upload size (2 MiB on free credits, 25 MiB on paid plans). The URL is stored encrypted; results show it without its query.

Chab reads the type from the file itself. A URL that returns a web page instead of a document fails with unsupported_file_type and costs nothing. Encrypted PDFs are refused like uploads (source_quarantined).

Pages

  • first_page: the first page to read, default 1.
  • max_pages: how many pages to read from there, default 10. Up to 50 for documents.ocr and documents.tables, up to 20 for documents.fields.

An image has one page. A PDF or a TIFF can have many; when the document has more pages than you asked for, the result has a partial_results warning that says which pages were read. Chab reads each page as an image, so scans and photos work. When a PDF has a text layer, Chab uses it to check spelling and numbers. Photos are turned upright by their camera orientation.

Pricing

The document tools cost the tokens the reading uses: 0.1 credit per 1,000 input tokens and 0.4 credit per 1,000 output tokens, rounded up once per request, at least 1 credit. A page image is about 260 input tokens; the text of a dense page is about 1,000 output tokens. One or two pages usually cost 1 credit.

Chab reserves credits for the pages you ask for (3,500 input and 4,096 output tokens a page; for fields, max_output_tokens) and charges what was used. A URL that ends in .png, .jpg, .jpeg, .webp or .heic, and an uploaded image, reserve one page. Set max_pages to keep the hold small for long PDFs.

A request that fails before the document is read costs nothing: a source that is missing, still scanning or not a supported type, a URL that cannot be downloaded, or a PDF that cannot be opened.

See Credits and Billing.

POST/v1/documents/ocr

Returns the text of each page as plain text and as Markdown. Markdown keeps headings, lists and tables. Pages with columns are read column by column. Signatures, stamps and pictures are noted in square brackets, such as [signature].

Required Access

  • Credits: reserved for max_pages pages, charged on the tokens used.
  • Scope: api:convert:write

Request

{
  "source": {
    "type": "url",
    "url": "https://upload.wikimedia.org/wikipedia/commons/b/bf/Einstein-Roosevelt-letter.png"
  }
}

Curl example:

curl -X POST https://www.chab.ai/v1/documents/ocr \
  -H "Authorization: Bearer CHAB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: einstein-letter-001" \
  -d '{"source":{"type":"url","url":"https://upload.wikimedia.org/wikipedia/commons/b/bf/Einstein-Roosevelt-letter.png"}}'

Fields:

  • source: required, see Sources.
  • first_page, max_pages: optional, see Pages.
  • callback_url, callback_secret, callback_events, and callback_notify_on_expiration: optional one-off operation callback fields.

OCR Result

{
  "data": {
    "result": {
      "source": {
        "type": "url",
        "url": "https://upload.wikimedia.org/wikipedia/commons/b/bf/Einstein-Roosevelt-letter.png",
        "filename": "Einstein-Roosevelt-letter.png",
        "format": "png",
        "byte_size": 292641
      },
      "page_count": 1,
      "first_page": 1,
      "pages_read": 1,
      "pages": [
        {
          "page": 1,
          "text": "Albert Einstein\nOld Grove Rd.\nNassau Point\nPeconic, Long Island\nAugust 2nd, 1939\n\nF.D. Roosevelt,\nPresident of the United States,\nWhite House\nWashington, D.C.\n\nSir:\n\nSome recent work by E.Fermi and L. Szilard, which has been com-\nmunicated to me in manuscript, leads me to expect that the element uran-\nium may be turned into a new and important source of energy...",
          "markdown": "Albert Einstein\nOld Grove Rd.\nNassau Point\nPeconic, Long Island\nAugust 2nd, 1939\n\nF.D. Roosevelt,\nPresident of the United States,\nWhite House\nWashington, D.C.\n\nSir:\n\nSome recent work by E.Fermi and L. Szilard, which has been com-\nmunicated to me in manuscript, leads me to expect that the element uran-\nium may be turned into a new and important source of energy...",
          "error": null
        }
      ],
      "usage": { "input_tokens": 407, "output_tokens": 697 }
    },
    "artifacts": [],
    "warnings": [],
    "result_expires_at": "2026-11-19T12:26:50+00:00"
  },
  "meta": {
    "request_id": "req_123"
  }
}

This scan of both pages of a typed letter cost 1 credit (407 input and 697 output tokens). A page that could not be read has text and markdown set to null and an error (provider_error or provider_temporarily_rate_limited), and the result has a partial_results warning; you pay only for the pages that were read. When no page can be read the operation fails with provider_unavailable and costs nothing. A page whose text is longer than 4,096 output tokens is cut off, with a result_truncated warning.

When the text of all pages is longer than about 600 KB, each page has the first 2,000 characters of its Markdown, pages_in_file is true, and the document-pages.jsonl artifact has every page in full.

POST/v1/documents/tables

Returns every table in the pages with its page number, column names and rows, and a CSV file of the tables: one CSV for one table, a ZIP with one CSV per table for several. A table that goes on to the next page with the same columns comes back as one table, with both pages in pages. Lists with prices, like on a receipt or an invoice, count as tables.

Required Access

  • Credits: reserved for max_pages pages, charged on the tokens used.
  • Scope: api:convert:write

Request

{
  "source": {
    "type": "url",
    "url": "https://upload.wikimedia.org/wikipedia/commons/f/f6/Wikimedia_Eesti_financial_statement_2016_%28English%29.pdf"
  },
  "first_page": 5,
  "max_pages": 2
}

Curl example:

curl -X POST https://www.chab.ai/v1/documents/tables \
  -H "Authorization: Bearer CHAB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: annual-report-tables-001" \
  -d '{"source":{"type":"url","url":"https://upload.wikimedia.org/wikipedia/commons/f/f6/Wikimedia_Eesti_financial_statement_2016_%28English%29.pdf"},"first_page":5,"max_pages":2}'

Fields:

  • source: required, see Sources.
  • first_page, max_pages: optional, see Pages.
  • callback_url, callback_secret, callback_events, and callback_notify_on_expiration: optional one-off operation callback fields.

Tables Result

{
  "data": {
    "result": {
      "source": {
        "type": "url",
        "url": "https://upload.wikimedia.org/wikipedia/commons/f/f6/Wikimedia_Eesti_financial_statement_2016_%28English%29.pdf",
        "filename": "Wikimedia_Eesti_financial_statement_2016_(English).pdf",
        "format": "pdf",
        "byte_size": 47490
      },
      "page_count": 14,
      "first_page": 5,
      "pages_read": 2,
      "table_count": 2,
      "tables": [
        {
          "index": 1,
          "page": 5,
          "pages": [5],
          "title": "Statement of financial position (In Euros)",
          "columns": ["", "31.12.2016", "31.12.2015", "Note"],
          "row_count": 21,
          "rows": [
            ["Assets", "", "", ""],
            ["Current assets", "", "", ""],
            ["Cash and cash equivalents", "15 397", "4 772", "2"],
            ["Receivables and prepayments", "3 759", "8 228", "3"],
            ["Total current assets", "19 156", "13 000", ""]
          ]
        },
        {
          "index": 2,
          "page": 6,
          "pages": [6],
          "title": "Statement of revenues and expenses (In Euros)",
          "columns": ["", "2016", "2015", "Note"],
          "row_count": 15,
          "rows": [
            ["Revenue", "", "", ""],
            ["Fees received from members", "189", "275", "7"],
            ["Grants and donations", "65 639", "83 457", "8"]
          ]
        }
      ],
      "files": [
        {
          "filename": "Wikimedia_Eesti_financial_statement_2016__English-tables.zip",
          "tables": [1, 2],
          "contents": ["table-1-page-5.csv", "table-2-page-6.csv"]
        }
      ],
      "failed_pages": [],
      "usage": { "input_tokens": 1583, "output_tokens": 764 }
    },
    "artifacts": [
      {
        "id": "art_01M7J5733HVSR0NY8VH7ZQ242J",
        "type": "zip",
        "role": "document_tables",
        "mime_type": "application/zip",
        "filename": "Wikimedia_Eesti_financial_statement_2016__English-tables.zip",
        "download_url": "/v1/operations/op_01M7J56VGK09XT1F1T9RVPAQNN/artifacts/art_01M7J5733HVSR0NY8VH7ZQ242J/download"
      }
    ],
    "warnings": [
      {
        "code": "partial_results",
        "message": "The document has 14 pages; pages 5 to 6 were read. Use first_page and max_pages for the others.",
        "field": "pages_read",
        "severity": "warning"
      }
    ],
    "result_expires_at": "2026-11-19T12:27:23+00:00"
  },
  "meta": {
    "request_id": "req_123"
  }
}

Rows are shortened here. These two pages of an annual report cost 1 credit. Cells keep the numbers as printed (15 397); every row has one cell per column. Pages that could not be read are listed in failed_pages with their error and cost nothing. When the pages have no table, tables is empty, there is no file, and the result has a partial_results warning.

POST/v1/documents/fields

Reads the whole document at once and returns the data you ask for: describe it in prompt, give its exact shape as a JSON schema, or both. Use it for invoices, receipts, IDs, contracts and forms. field_pages names, for each top-level field, the pages its value came from. The answer is checked against the schema; when it does not match, Chab asks once more with the problems.

Required Access

  • Credits: reserved for max_pages pages and max_output_tokens, charged on the tokens used.
  • Scope: api:convert:write

Request

{
  "source": {
    "type": "url",
    "url": "https://upload.wikimedia.org/wikipedia/commons/e/ee/Italian_supermarket_receipt_showing_value-added_tax_%28IVA%29_categories.jpg"
  },
  "prompt": "The receipt date, the total, the VAT and each item with its price.",
  "schema": {
    "type": "object",
    "properties": {
      "date": { "type": ["string", "null"] },
      "total": { "type": ["number", "null"] },
      "vat": { "type": ["number", "null"] },
      "items": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": { "name": { "type": "string" }, "price": { "type": "number" } },
          "required": ["name", "price"]
        }
      }
    },
    "required": ["date", "total", "vat", "items"]
  }
}

Curl example:

curl -X POST https://www.chab.ai/v1/documents/fields \
  -H "Authorization: Bearer CHAB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: receipt-fields-001" \
  -d '{"source":{"type":"url","url":"https://upload.wikimedia.org/wikipedia/commons/e/ee/Italian_supermarket_receipt_showing_value-added_tax_%28IVA%29_categories.jpg"},"prompt":"The receipt date, the total, the VAT and each item with its price."}'

Fields:

  • source: required, see Sources.
  • prompt: what to get, in plain words, 3 to 4,000 characters.
  • schema: a JSON schema for the data, with type: object at the root, up to 32 KB. prompt, schema or both are required.
  • first_page, max_pages: optional, see Pages. Up to 20 pages.
  • max_output_tokens: optional, 256 to 16,384; defaults to 4,096.
  • callback_url, callback_secret, callback_events, and callback_notify_on_expiration: optional one-off operation callback fields.

The prompt and the schema are stored encrypted for the worker and are not part of the operation's request summary.

Fields Result

{
  "data": {
    "result": {
      "source": {
        "type": "url",
        "url": "https://upload.wikimedia.org/wikipedia/commons/e/ee/Italian_supermarket_receipt_showing_value-added_tax_%28IVA%29_categories.jpg",
        "filename": "Italian_supermarket_receipt_showing_value-added_tax_(IVA)_categories.jpg",
        "format": "jpeg",
        "byte_size": 984810
      },
      "page_count": 1,
      "first_page": 1,
      "pages_read": 1,
      "data": {
        "date": null,
        "total": 11.85,
        "vat": 1.12,
        "items": [
          { "name": "ACQUA S.ANGELO NATUR", "price": 1.32 },
          { "name": "MILK PRO PORRIDGE AV", "price": 1.65 },
          { "name": "MILK PRO PORRIDGE AV", "price": 1.65 },
          { "name": "LINDT TAVOLETTA LATT", "price": 2.85 },
          { "name": "CRIK CROK STILE FATT", "price": 2.85 },
          { "name": "MELE GRANNY SMITH [C", "price": 1.53 }
        ]
      },
      "field_pages": { "date": [], "total": [1], "vat": [1], "items": [1] },
      "usage": { "input_tokens": 510, "output_tokens": 186 }
    },
    "artifacts": [],
    "warnings": [],
    "result_expires_at": "2026-11-19T12:29:12+00:00"
  },
  "meta": {
    "request_id": "req_123"
  }
}

This photo of a receipt cost 1 credit. The receipt shows no date, so date is null and its field_pages list is empty. When the answer still does not match the schema after the second try, the operation fails with extraction_failed and you pay the tokens used.

Document Errors

Code When Charge
validation_failed A field is missing or wrong, the URL is not public https, or first_page is past the last page None
not_found, file_expired, source_scan_pending, source_scan_failed The file or artifact cannot be read None
unsupported_file_type Not a PDF, PNG, JPEG, WebP, TIFF or HEIC file None
unsupported_file_content The PDF or image cannot be opened None
source_too_large Larger than your plan's upload size, or an image over 50 megapixels None
source_quarantined The file did not pass the virus check, or it is an encrypted PDF None
target_fetch_blocked, target_timeout The URL could not be downloaded None
provider_unavailable No page could be read right now; try again later None
extraction_failed The fields did not match the schema after two tries The tokens used