Learning resourcesReviewed · xAI

Receipts to Spreadsheet

Receipts to Spreadsheet is an xAI guide for developers building an AI receipt scanner, but its automated checks cannot guarantee accurate records. It describes a TypeScript application that turns photos and PDF invoices into spreadsheet rows, checks the extracted values with Zod, compares two Grok reads and lets people correct the results before exporting CSV.

Researched 15 Nov 2026

In short.

Receipts to Spreadsheet is an xAI tutorial for developers building receipt and invoice extraction, with human review still needed because matching reads and valid totals can both be wrong. The example combines structured output, arithmetic checks, validation retries and an editable spreadsheet. Standard processing uses grok-4.7; batch processing uses grok-4.3 and does not retry failed validation. The page reports timings and costs from fictional samples, but accuracy on real documents, current pricing and production readiness are not established. No code was executed.

Researched and written by an AI model and checked by a second AI model. How it works

Covers the complete documentation page at [https://docs.x.ai/cookbook/examples/receipts-to-spreadsheet.md], captured as selected-page.txt. Linked pages, repository files, licence files, API terms and live endpoints are excluded. The page supplies no licence notice or release date. Its runtime and cost figures are attributed to the author; setup, extraction accuracy, exports, cancellation, billing and file deletion remain untested.

The overview

identity

Receipts to Spreadsheet is an xAI cookbook guide at [https://docs.x.ai/cookbook/examples/receipts-to-spreadsheet.md]. It teaches an example application for extracting receipt photos and PDF invoices through the Grok API.

The resource is primarily instructional. It describes shared TypeScript extraction code, a browser spreadsheet and a terminal interface; it does not establish a hosted receipt-processing service.

assessment

Its strongest teaching point is the separation between correctly shaped data and credible values. A schema constrains the fields, arithmetic checks catch inconsistencies, and a second read identifies disagreements for a person to inspect.

It is a useful implementation reference for document-extraction applications. The fictional samples and author-reported results do not establish accounting accuracy or readiness for unattended production use.

users

The guide suits JavaScript and TypeScript developers building expense tools, invoice intake or other applications that turn documents into structured records. Experienced developers can examine its validation, retry, streaming and batch-processing patterns.

Beginners get a concrete browser demonstration, but setup still involves Node.js, terminal commands, dependencies and an API key. The documented interface supports manual review; suitability for a nontechnical team operating it without developer support is not assessed.

capabilities

The documented schema extracts vendor, date, currency, line items, subtotal, tax, tip and total. Checks cover parseable dates, recognized currency codes, quantity multiplied by price, line-item sums and the final total, allowing rounding to the currency's smallest unit.

The browser shows disagreements in yellow and failed checks in red. Users can compare both reads, choose or edit values, add missed line items and export corrected CSV. The terminal saves CSV plus JSON containing line items and disagreements. Streaming progress, cancellation and batch processing are also described.

Using it

requirements

The page requires Node.js 22.13 or later and an xAI API key supplied through XAI_API_KEY or a .env file at the repository root. It names the SDK and Zod as dependencies, without specifying their package versions.

The example assumes access to its repository files and the relevant Grok APIs. Standard reads use grok-4.7, while batch mode uses grok-4.3. Account eligibility, rate limits, deployment capacity and exact dependency compatibility are unknown.

mechanism

The Receipt Zod schema is converted with z.toJSONSchema() for the API's output constraints. After generation, response.toJson(Receipt) applies local validation, including refinements for currency and arithmetic. When validation fails, the problems and conversation history from response.toInput() are sent back for another look. A result that still fails is retained with its problems.

Each receipt receives two separately sampled reads in parallel. The comparison favors the result with fewer validation problems and records differing fields, ignoring case, spacing and punctuation. Line items are paired by name or amount before comparison. Ordinary processing handles three receipts concurrently.

Photos are sent as high-detail images. PDFs are uploaded through the Files API with a stated one-hour expiry. Batch mode submits both reads together, polls every five seconds and validates Chat Completions-format results directly with Zod, without validation retries. The browser receives progress through server-sent events.

setup

The documented setup is to enter examples/receipts-to-spreadsheet/typescript, configure the API key, run npm install and then npm run web. The browser interface opens at [http://localhost:3000], where users can read the samples or supply photos and PDFs.

For terminal use, the page gives npm start -- ./receipt.jpg ./invoice.pdf. With no file arguments, it reads eight bundled samples. The --batch option enables batch processing. The captured page does not provide a repository checkout URL, so obtaining the source is a prerequisite it leaves implicit. These instructions were not executed.

example

One fictional sample has a salsa stain covering a price. The page reports that an initial read can omit that price, causing the subtotal check to fail; a follow-up read can infer it from the subtotal. This illustrates how validation can direct another extraction attempt, although an inferred value still needs scrutiny.

Other examples include an ambiguous Canadian date, 05/10/26, and a hardware line, WOOD SCREWS #8 X 2, where it is ambiguous whether X 2 is a quantity or the screws' length; the page reports the two reads tend to split on it. All eight samples are fabricated: five were rendered from HTML, and three photos were generated with grok-imagine-image-2.0. They do not constitute a real-world accuracy benchmark.

Assessment & evidence

limitations

Two reads can agree on the same mistake, and incorrect values can still satisfy arithmetic checks. A date can parse while its intended day and month remain ambiguous. Disagreements are useful review signals, but agreement is not proof of correctness.

Accuracy across real receipts, languages, handwriting and invoice layouts is not assessed. The described schema does not establish support for invoice-specific fields such as invoice numbers or payment terms. Authentication, persistent storage and production deployment controls are also not described.

Batch mode uses a different model from ordinary processing and does not retry reads that fail validation, because a second round would wait in the queue again. Comparable quality between the two modes is not established.

reasoning

The design makes extraction more inspectable by combining structural constraints, arithmetic rules and separately sampled outputs. These signals address different failure types, but none establishes that the extracted record faithfully represents the original document.

The page uses agreement as a confidence signal because grok-4.7 does not return log probabilities. It provides no calibration showing how agreement predicts accuracy. It reports using low reasoning effort because receipts are short and the checks catch the misreads that more reasoning would catch, noting that a read at the default effort took about three times as long; the evidence does not establish that tradeoff for more complex documents.

alternatives

Within this example, the browser is the documented option for inspecting and correcting cells, while the terminal produces files suitable for further processing. Batch mode is presented for larger sets, with different model behavior and potentially much longer waits.

The page does not compare other OCR services, accounting applications or local extraction models. Relative accuracy, privacy, integration effort and cost against those alternatives are unknown.

evidence

The evidence is the complete documentation page at [https://docs.x.ai/cookbook/examples/receipts-to-spreadsheet.md]. It describes the application architecture, setup, sample provenance and author-reported timings and costs.

Repository source files, linked documentation and live API responses are outside this evidence. Implementation behavior, export correctness, cancellation, billing and upload deletion were not independently verified. No code was executed.

Access & freshness

costs

The author reports that eight samples took 20–50 seconds and cost US$0.07–0.10. A two-receipt batch reportedly took about 35 seconds and cost about US$0.02 at the batch price used then. The page also warns that a batch can take up to a day. These are reported examples, not independently reproduced measurements or current price guarantees.

The application totals API-reported costs using usage.cost_usd for ordinary responses and cost_in_usd_ticks for batch results, with ten billion ticks per dollar. Two reads and any retries contribute to usage. Current unit prices, typical costs on real invoices and hosting costs are unknown.

rights

The supplied page does not state a licence for the documentation, application code or sample assets. Permissions for reuse, modification, commercial use and redistribution are therefore unknown.

The page says uploaded PDFs expire after one hour. It does not establish broader API retention, training-use terms or treatment of image inputs. The stated upload expiry should not be interpreted as a complete data-handling policy.

freshness

The page was captured on 15 November 2026 at 04:25:04.481 UTC. It names Node.js 22.13 or later, grok-4.7 for ordinary reads and grok-4.3 for batches, but gives no publication date, update date or application release identifier.

The capture date establishes when this documentation was obtained. Continued model availability, current prices and compatibility with later SDK or Zod releases remain unknown.

actions

Use the fictional samples to understand the review interface, then assess representative documents from the intended workload. Compare both flagged and unflagged fields with the originals, including dates, inferred prices and line items that both reads might miss.

Before adopting the example, confirm source availability, licence terms, current model access, pricing and document-handling terms. Assess ordinary and batch modes separately, and establish human review requirements before sending extracted records into bookkeeping or other downstream systems.

Evidence for this report

selected-page.txtselected · checked 2026-11-15