# parserkit

> Document parsing API. Send a PDF, photo, Office file or email; get checked JSON, XLSX, CSV, QuickBooks and Xero files back. Totals, line items and balances are math-checked, and each value points at the page and box it came from.

Base URL: https://api.parserkit.com
Auth: `Authorization: Bearer $PARSERKIT_API_KEY` (keys start with `pkit_live_`)
OpenAPI: https://api.parserkit.com/openapi.json (request bodies, every preset's data schema, every error code)

## Parse a file

```sh
curl https://api.parserkit.com/v1/parse \
  -H "Authorization: Bearer $PARSERKIT_API_KEY" \
  -F file=@invoice.pdf -F preset=invoice
```

- Send exactly one of: `file` (multipart, up to 25 MB), `file_url` (public http(s) URL, up to 100 MB) or `upload_id` (see Large files).
- Pick exactly one of: `preset` (invoice, receipt, bank_statement, resume, purchase_order, bill_of_lading, generic_table), `schema_id` (a saved schema) or `schema` (an inline JSON Schema, optional `field_rules`).
- JSON bodies work too: `{"file_url": "https://...", "preset": "receipt"}` with `Content-Type: application/json`.
- Optional: `password` (never stored), `vault` (try saved passwords, default false), `gl_accounts` (up to 500 code/name pairs to categorize lines), `enrich`, `retain_source` (default true), `webhook_url` (https), `metadata` (up to 20 string keys, returned as-is).
- Up to 250 pages per job, and a job never bills more. .eml, .msg and .zip files become one job with several `documents`.

## Waiting and polling

- `?wait=0..60` (default 60): 200 with the job when it finishes in time, else 202 with `Location` and `Retry-After`.
- Poll `GET /v1/jobs/{id}?wait=25` until `status` is `succeeded` or `failed`.
- A job that fails within the wait answers with its error status and `{"error": {...}, "job": {...}}`.
- `Idempotency-Key: <your id>` on POST /v1/parse and POST /v1/uploads replays the same job or upload for 24 hours; the same key with a different request is 409 `IDEMPOTENCY_CONFLICT`. For an `upload_id` the parse is matched on the file's SHA-256 and size, so the same file through a new upload replays.

## The job

`status`, `pages`, `cost_usd`, `verification_status` (verified, partial, unverified, discrepancy), `data` and `verification` (when the job holds exactly one document; null for .eml/.msg/.zip with several), `documents[]` (each with `data`, `provenance`, `verification`; `verification_status` is the worst of them), `data_omitted` (true when the result is over 3 MiB: `data`, `verification` and each document's `data`, `provenance` and `verification` are null, `warnings` holds the first 100, and `data_url` is a signed link to the whole `{documents, warnings}`, re-signed on every read and valid until `data_url_expires_at`), `outputs[]` (signed links to output.json, output.xlsx, output.csv, quickbooks.csv, xero.csv; re-signed on every read), `duplicate`, `error` ({code, message}), `metadata`.

`GET /v1/jobs?cursor=&limit=1..100&status=&source=` lists jobs newest first; follow `next_cursor`.

## Large files

1. `POST /v1/uploads` with `{"file_name": "scan.pdf", "bytes": 48213004}` returns `upload_id` and a signed `url`. Over 100 MB is 413 FILE_TOO_LARGE; at most 100 links wait for their file at once.
2. `PUT` the file to `url` once, within the hour, with a `Content-Length` header. A second PUT is 409 UPLOAD_ALREADY_RECEIVED (with `upload_id`, `bytes` and `sha256`); a PUT while another runs is 409 CONFLICT with `Retry-After: 30`; an expired link is 410 UPLOAD_EXPIRED.
3. Within 20 hours, `POST /v1/parse` with `{"upload_id": "...", "preset": "bank_statement"}`. Each upload feeds one job.

Replaying POST /v1/uploads with its `Idempotency-Key` answers by state: 201 with the same link while it waits for the PUT; 409 UPLOAD_ALREADY_RECEIVED once the file arrived (check `sha256`, go on with `upload_id`); 409 CONFLICT while a PUT runs, even past expiry, since that PUT may still finish; 410 UPLOAD_EXPIRED once it expired and no PUT runs (start over with a new key).

## Schemas, inboxes, vault

- `POST /v1/schemas`, `GET`, `PATCH` and `DELETE /v1/schemas/{id}`. PATCH takes the `version` you read: if the schema moved on, 409 CONFLICT with `error.version` and nothing changes.
- `POST /v1/schemas/from-sample` proposes a schema from the first 3 pages of the first document, for 1 page, up to 30 a UTC day per account. Pages or documents past that are left out with a SAMPLE_TRUNCATED warning.
- Inboxes (`/v1/inboxes`) are Pro to create or change: at most 20 live inboxes and 100 addresses ever, else 409 with `error.limit`.
- Saving a vault password (`POST /v1/vault/passwords`) is Pro, at most 100.
- Pro means the effective plan: Pro until 3 days after the period ends. Otherwise 403 PLAN_REQUIRED.
- DELETE answers 200 `{"id": "...", "deleted": true}`. Lists answer `{"items": [...], "next_cursor": ...}`.

## Webhooks

Events: `job.succeeded`, `job.failed`, `job.discrepancy_flagged`. Body: `{"id", "type", "created_at", "data": <job>}`.
Verify `Parserkit-Signature: t=<unix>,v1=<hex>` where v1 = HMAC-SHA256(webhook secret, "<t>.<raw body>"); reject old timestamps. `Idempotency-Key` is the event id and stays the same across retries.

## Errors

`{"error": {"code": "...", "message": "...", "request_id": "..."}}`. Match on `code`, never the message. Every response has a `Request-Id` header; quote it when you report a problem.
Requests: 400 INVALID_REQUEST / INVALID_SCHEMA, 401 UNAUTHORIZED, 402 INSUFFICIENT_CREDIT, 403 FORBIDDEN / PLAN_REQUIRED / HTTPS_REQUIRED, 404 NOT_FOUND / SOURCE_NOT_FOUND / JOB_NOT_FOUND, 405 METHOD_NOT_ALLOWED, 408 REQUEST_TIMEOUT, 409 IDEMPOTENCY_CONFLICT / CONFLICT / UPLOAD_ALREADY_RECEIVED, 410 UPLOAD_EXPIRED, 413 FILE_TOO_LARGE, 415 UNSUPPORTED_FORMAT, 422 PASSWORD_REQUIRED / TOO_MANY_PAGES / CORRUPT_FILE / LLM_REFUSED, 429 RATE_LIMITED / BUSY / CONTENT_REFUSALS, 500 INTERNAL, 501 NOT_IMPLEMENTED, 502 LLM_UNAVAILABLE / OCR_UNAVAILABLE, 503 CONTAINER_UNAVAILABLE, 504 TIMEOUT.
Failed jobs: 402 INSUFFICIENT_CREDIT, 409 SOURCE_CHANGED, 413 FILE_TOO_LARGE, 415 UNSUPPORTED_FORMAT, 422 CORRUPT_FILE / PASSWORD_REQUIRED / TOO_MANY_PAGES / TOO_MANY_SCANNED_PAGES / SOURCE_NOT_FOUND / LLM_REFUSED / BUDGET_EXHAUSTED, 429 RATE_LIMITED / CONTENT_REFUSALS, 500 INTERNAL, 502 LLM_UNAVAILABLE / OCR_UNAVAILABLE, 503 CONTAINER_UNAVAILABLE, 504 TIMEOUT.
429: honor `Retry-After`; daily caps reset at UTC midnight, so it can be up to 86400 seconds. 5xx: retry later.

## Pricing

$0.02 per page, $0.01 after 5,000 pages a month, from a prepaid wallet ($1 free credit at signup). Pro: $29/month with 1,500 pages. Failed jobs and exact duplicates are free.
