Products · DocFlow app

JSON and CSV output

Preview the final JSON, metadata and CSV before paying.

Version 1 · The app that connects the servicesDesigned, not builtModule 6 of 15

InterfacesAPI SpecSections

API Spec Designed

Base address: https://01scale.com/api/docflow/v1. Open an endpoint for its inputs, constraints, errors and samples.

POST/documentsStart a document

Starts the DocFlow process for one invoice: creates the document and its upload in the Upload service with DocFlow's limits. Signed in

Scope: docflow:write

Inputs

file_namebodystringrequired
The invoice's name.
As Upload's.
mimebodystringrequired
Its type.
application/pdf, image/png or image/jpeg.
sizebodyintegerrequired
Its size.
1 to 10 MB.
Idempotency-Keyheaderstringoptional
Makes a retry safe.
1 to 255 characters.

What it does

  • Calls Upload POST /files with the caller's token and accept = PDF, PNG, JPEG, 10 MB, 10 pages.
  • Records the document as pending_upload with the file's ID; returns Upload's upload link.

Responses

  • 201Created. document and upload (Upload's link and headers).
  • 413file_too_large Passed on from Upload.
  • 415unsupported_file_type Passed on from Upload.
  • 422validation_failed An input is malformed.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

POST /api/docflow/v1/documents HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>
Content-Type: application/json

{
  "file_name": "acme-invoice-0042.pdf",
  "mime": "application/pdf",
  "size": 248913
}

Sample response

{
  "document": {
    "id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
    "file_name": "acme-invoice-0042.pdf",
    "status": "pending_upload",
    "next_action": "upload",
    "file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "job_id": null,
    "review_task_id": null,
    "order_id": null,
    "created_at": "2026-11-17T09:14:07Z",
    "updated_at": "2026-11-17T09:17:03Z"
  },
  "upload": {
    "url": "https://01scale-uploads.s3.us-east-1.amazonaws.com/users/\u2026/original.pdf?X-Amz-Signature=\u2026",
    "method": "PUT",
    "headers": {
      "Content-Type": "application/pdf",
      "Content-Length": "248913"
    },
    "expires_at": "2026-11-17T09:19:07Z"
  }
}
POST/documents/{documentId}/upload-completeConfirm the upload and start extraction

Called by the upload component when the bytes are sent. Signed in

Scope: docflow:write

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.

What it does

  • Calls Upload POST /files/{fileId}/complete. If the file is rejected, the document is rejected with Upload's reason.
  • If ready, calls Extraction POST /jobs with reference: docflow:{documentId} and sets the document extracting. It asks with hold: true and a delegated token for the owner (act: service:docflow), so DocFlow holds the results until the order is paid (DOCFLOW-V1-E5-05).
  • Idempotent: a document already past this step is returned unchanged.

Responses

  • 200The upload was checked. document with status extracting or rejected.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 409upload_missing Passed on from Upload: the file has not arrived.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

POST /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/upload-complete HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "document": {
    "id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
    "file_name": "acme-invoice-0042.pdf",
    "status": "extracting",
    "next_action": "extract",
    "file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "job_id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
    "review_task_id": null,
    "order_id": null,
    "created_at": "2026-11-17T09:14:07Z",
    "updated_at": "2026-11-17T09:17:03Z"
  }
}
GET/documentsList my documents

The caller's documents, newest first, with a status and the next action for each. Signed in

Scope: docflow:read

Inputs

statusquerystringoptional
Filter.
A document status.
cursor, limitquerystring, integeroptional
Paging.
limit 1 to 100.

What it does

  • Read only. next_action is upload, extract, review, results, pay or download.

Responses

  • 200Always. data[] of documents and next_cursor.
  • 401not_authenticated No valid access token.

Sample request

GET /api/docflow/v1/documents HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "data": [
    {
      "id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
      "file_name": "acme-invoice-0042.pdf",
      "status": "paid",
      "next_action": "download",
      "file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
      "job_id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
      "review_task_id": "0193b0f2-3c4d-7e5f-8a6b-7c8d9e0f1a2b",
      "order_id": "0193b120-5a6b-7c7d-8e8f-9a0b1c2d3e4f",
      "created_at": "2026-11-17T09:14:07Z",
      "updated_at": "2026-11-17T09:17:03Z"
    }
  ],
  "next_cursor": null
}
GET/documents/{documentId}Get one document

A document, its status, and the IDs of its parts in each service. Signed in

Scope: docflow:read

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.

What it does

  • Read only.

Responses

  • 200The document is the caller's. document.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 401not_authenticated No valid access token.

Sample request

GET /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "document": {
    "id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
    "file_name": "acme-invoice-0042.pdf",
    "status": "paid",
    "next_action": "download",
    "file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "job_id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
    "review_task_id": "0193b0f2-3c4d-7e5f-8a6b-7c8d9e0f1a2b",
    "order_id": "0193b120-5a6b-7c7d-8e8f-9a0b1c2d3e4f",
    "created_at": "2026-11-17T09:14:07Z",
    "updated_at": "2026-11-17T09:17:03Z"
  }
}
POST/documents/{documentId}/retry-extractionRetry a failed extraction

Starts a new extraction job after the last one failed. Signed in

Scope: docflow:write

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.

What it does

  • Calls Extraction POST /jobs for the same file, again with hold: true and a delegated token (DOCFLOW-V1-E5-05); stores the new job's ID; the document is extracting again.

Responses

  • 202A new job started. document.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 409not_failed The last extraction did not fail.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

POST /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/retry-extraction HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "document": {
    "id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
    "file_name": "acme-invoice-0042.pdf",
    "status": "extracting",
    "next_action": "extract",
    "file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "job_id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
    "review_task_id": null,
    "order_id": null,
    "created_at": "2026-11-17T09:14:07Z",
    "updated_at": "2026-11-17T09:17:03Z"
  }
}
POST/documents/{documentId}/complete-reviewFinish review

Re-checks the corrected values and completes the review. The results are built from Review's values whenever they are looked at; nothing is stored. Signed in

Scope: docflow:write

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.
confirm_failed_checksbodybooleanoptional
The person confirmed values that still fail a check are as printed.
Default false.

What it does

  • Reads the review task, then calls Extraction POST /validations with its values and the job's ID.
  • If a check fails and confirm_failed_checks is false, answers 409 with the failed checks; nothing changes.
  • Otherwise calls Review POST /tasks/{taskId}/complete (with checks_overridden) and sets the document reviewed.
  • Safe to retry: completing an already completed task returns it unchanged, and a document already reviewed or paid is returned as it is.

Responses

  • 200Review completed. document (status reviewed).
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 409fields_unresolved Passed on from Review.
  • 409checks_failed failed_checks[] lists them; send confirm_failed_checks: true to keep the values.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

POST /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/complete-review HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>
Content-Type: application/json

{
  "confirm_failed_checks": false
}

Sample response

{
  "document": {
    "id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
    "file_name": "acme-invoice-0042.pdf",
    "status": "reviewed",
    "next_action": "pay",
    "file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "job_id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
    "review_task_id": "0193b0f2-3c4d-7e5f-8a6b-7c8d9e0f1a2b",
    "order_id": null,
    "created_at": "2026-11-17T09:14:07Z",
    "updated_at": "2026-11-17T09:17:03Z"
  }
}
GET/documents/{documentId}/outputsResults status

Whether results can be shown, whether download is unlocked, and whether the current values pass every check. Signed in

Scope: docflow:read

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.

What it does

  • Read only. locked is true until the order is paid. checks comes from Extraction POST /validations on Review's current values, so a later correction that breaks a rule is shown at once.
  • last_changed_at is the latest correction in Review, after the review or after payment.

Responses

  • 200The review is complete. locked, formats, checks (passed, failed[]) and last_changed_at.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 409outputs_not_ready The review is not complete.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

GET /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/outputs HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "locked": false,
  "formats": [
    "json",
    "csv"
  ],
  "checks": {
    "passed": true,
    "failed": []
  },
  "last_changed_at": "2026-11-17T09:21:40Z"
}
GET/documents/{documentId}/outputs/{format}/previewPreview the JSON or CSV

The results, shown on screen: a short preview before paying, the full results after. Signed in

Scope: docflow:read

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.
formatpathstringrequired
Which output.
json or csv.

What it does

  • Builds it on demand: reads the final values from Review GET /tasks/{taskId}?all=true and the model, prompt version and page count from Extraction GET /jobs/{jobId}, re-runs Extraction POST /validations (with job_id) on the current values, then builds the format and validates the JSON against schemas/invoice-v1.json. Nothing is stored (ARCHITECTURE.md §12.8), so it always reflects the latest corrections.
  • Until the order is paid, the preview holds four fields only (vendor_name, invoice_number, invoice_date, total), and says how many fields and line items are held back; the CSV has those four columns. The limit is applied on the server, so the full results cannot be read before payment (Nikhil's decision, 22 Nov 2026, changing DOCFLOW-V1-E5-03 AC1).

Responses

  • 200The review is complete. application/json or text/csv with Content-Disposition: inline. Before payment the JSON adds preview: {limited: true, fields_hidden, line_items_hidden} and the CSV has X-Preview-Limited: true.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 409outputs_not_ready The review is not complete.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

GET /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/outputs/json/preview HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "data": {
    "vendor_name": "Acme Supplies Ltd",
    "invoice_number": "INV-0042",
    "invoice_date": "2026-11-02",
    "currency": "USD",
    "subtotal": "1150.00",
    "tax_total": "80.00",
    "total": "1230.00",
    "line_items": [
      {
        "description": "Paper, A4",
        "quantity": "10",
        "unit_price": "115.00",
        "amount": "1150.00"
      }
    ]
  },
  "metadata": {
    "document_id": "0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
    "file_name": "acme-invoice-0042.pdf",
    "pages": 2,
    "model": "claude-opus-5-5",
    "prompt_version": "extract-invoice/v1",
    "extracted_at": "2026-11-17T09:14:41Z",
    "reviewed_at": "2026-11-17T09:16:02Z",
    "reviewed_by": "0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e",
    "last_changed_at": "2026-11-17T09:21:40Z",
    "fields_flagged": 3,
    "fields_corrected": 1,
    "fields": {
      "total": {
        "confidence": 0.3,
        "corrected": true
      },
      "vendor_name": {
        "confidence": 0.97,
        "corrected": false
      }
    }
  }
}
GET/documents/{documentId}/outputs/{format}/downloadDownload the JSON or CSV

Locked until the order is paid, checked on the server every time. Signed in

Scope: docflow:read

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.
formatpathstringrequired
Which output.
json or csv.

What it does

  • Reads the order from Payment; if it is not paid, answers 402.
  • Builds it on demand: reads the final values from Review GET /tasks/{taskId}?all=true and the model, prompt version and page count from Extraction GET /jobs/{jobId}, re-runs Extraction POST /validations (with job_id) on the current values, then builds the format and validates the JSON against schemas/invoice-v1.json. Nothing is stored (ARCHITECTURE.md §12.8), so it always reflects the latest corrections.
  • Returns the file itself as an attachment named {document}-result.{format}, and records delivery.downloaded (DOCFLOW-V1-E7-02). A generated result is a few kilobytes, so it is returned directly: no stored copy, no storage link. Stored files, like the original upload, still move only by short-lived links.

Responses

  • 200Paid. The file, with Content-Disposition: attachment; filename="acme-invoice-0042-result.csv" and Cache-Control: no-store.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 402payment_required The order is not paid.
  • 409outputs_not_ready The review is not complete.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

GET /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/outputs/csv/download HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

HTTP/1.1 200 OK
Content-Type: text/csv; charset=utf-8
Content-Disposition: attachment; filename="acme-invoice-0042-result.csv"
Cache-Control: no-store

document_id,vendor_name,…
POST/documents/{documentId}/checkoutStart payment

Sets the price and asks Payment for a checkout page. Signed in

Scope: docflow:write

Inputs

documentIdpathuuidrequired
The document.
A document of the caller's.

What it does

  • Requires status reviewed.
  • Calls Payment POST /orders from DocFlow's server with a delegated token for the person (Payment accepts no other kind), the price, $5.00 (500 cents, from configuration), reference: docflow:{documentId}, and success and cancel addresses; stores the order's ID.

Responses

  • 201Order ready. order_id and checkout_url.
  • 404document_not_found No such document, or it belongs to another user. The same answer in both cases.
  • 409already_paid Go straight to success.
  • 409not_reviewed The review is not complete.
  • 503dependency_unavailable A platform service could not be reached. Nothing was changed; safe to retry.
  • 401not_authenticated No valid access token.

Sample request

POST /api/docflow/v1/documents/0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c/checkout HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "order_id": "0193b120-5a6b-7c7d-8e8f-9a0b1c2d3e4f",
  "checkout_url": "https://checkout.stripe.com/c/pay/cs_test_\u2026"
}
GET/statsMy DocFlow totals

For the account page. Signed in

Scope: docflow:read

Inputs

None.

What it does

  • Read only.

Responses

  • 200Always. documents_processed: documents that reached reviewed or paid.
  • 401not_authenticated No valid access token.

Sample request

GET /api/docflow/v1/stats HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "documents_processed": 4
}
POST/webhooks/{service}Receive service events

Where platform services tell DocFlow that something finished, so the process moves on without the browser. Service

Scope: None: HMAC signature

Inputs

servicepathstringrequired
Who sent it.
extraction, review, payment, identity or delivery.
X-01scale-Signatureheaderstringrequired
Proves the event came from the platform.
HMAC-SHA256 of the raw body, compared in constant time.
event_id, type, databodyuuid, string, objectrequired
The event.
Processed once per event_id.

What it does

  • No person is present, so each step uses a delegated token for the document's owner from Identity (act: service:docflow; decision on #24).
  • Acts only on events about the document's current work: an extraction event whose job_id is not the document's job_id, or a payment event whose order_id is not its order_id, is acknowledged and ignored. A late failure from a retried job, or the expiry of an earlier order, changes nothing.
  • extraction.job.completed: reads the fields with Extraction GET /jobs/{jobId}/fields, creates a Review task with Review POST /tasks and hold: true (Idempotency-Key docflow:{documentId}:{jobId}; DOCFLOW-V1-E5-05) and sets the document needs_review; with nothing flagged it still creates the task, so every document is reviewed the same way.
  • extraction.job.failed: sets extraction_failed.
  • payment.order.paid: releases the held results, Extraction POST /jobs/{jobId}/release and Review POST /tasks/{taskId}/release (each safe to repeat; DOCFLOW-V1-E5-05), then sets paid and asks Delivery POST /messages for the order_paid email, keyed by the event's ID. If a release fails, the event is retried; downloads already work, because DocFlow builds them as the holder.
  • payment.order.expired or failed: clears the order so Pay starts a new one.
  • identity.user.deleted: deletes that user's documents. There are no stored results to delete: Extraction and Review delete their own data.
  • Other types are acknowledged and ignored.

Responses

  • 200Accepted, including a repeat. No body.
  • 401invalid_signature The signature is missing or wrong.

Sample request

POST /api/docflow/v1/webhooks/payment HTTP/1.1
X-01scale-Signature: sha256=8c1f...
Content-Type: application/json

{
  "event_id": "0193b121-0000-7000-8000-00000000aaaa",
  "type": "payment.order.paid",
  "data": {
    "order_id": "0193b120-5a6b-7c7d-8e8f-9a0b1c2d3e4f",
    "reference": "docflow:0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c"
  }
}

Sample response

HTTP/1.1 200 OK

Errors

Every error has the same shape and a stable code to branch on.

{
  "type": "https://01scale.com/errors/payment_required",
  "title": "Payment required",
  "status": 402,
  "detail": "Pay to download these results.",
  "code": "payment_required",
  "request_id": "req_0193a61f9c2e"
}

Handled without an endpoint

Building the JSON (DOCFLOW-V1-E5-01)
data holds the final values in the invoice v1 shape; metadata holds document_id, file_name, pages, model, prompt_version, extracted_at, reviewed_at, reviewed_by, fields_flagged, fields_corrected, and per field confidence and corrected. Built on each request and validated against schemas/invoice-v1.json before it is returned; metadata.last_changed_at is the latest correction in Review.
Building the CSV (DOCFLOW-V1-E5-02)
Columns in this order: document_id, vendor_name, vendor_address, vendor_tax_id, invoice_number, invoice_date, due_date, bill_to_name, bill_to_address, currency, subtotal, tax_total, total, payment_terms, line_number, line_description, line_quantity, line_unit_price, line_amount. RFC 4180 quoting, UTF-8 with a byte-order mark, CRLF line ends; cells starting with =, +, -, @, tab or carriage return are prefixed with '.
Success page (DOCFLOW-V1-E7-01)
Polls Payment GET /orders/{orderId} every 2 seconds for up to 30 seconds, then says 'We'll email you when it's ready'; shows the email's status from Delivery.
Which token each step uses (decisions on #24 and #21)
Steps the person starts (upload, retry, complete review, checkout, preview, download) use their own token, except Payment and Delivery, which take only a delegated token. Steps after an event (create the review task, send the email) use a delegated token for the document's owner. So do starting an extraction and reading results for the preview, the downloads and the checks, because DocFlow holds the results until payment and only the holder reads them in full (DOCFLOW-V1-E5-05). Every call goes through https://01scale.com/api/….
Pages
/documents, /documents/new (upload, with the file's preview once checked), /documents/{id} (extraction, with the preview beside the fields), /documents/{id}/review, /documents/{id}/results, /documents/{id}/pay, /documents/{id}/success. Each composes the services' components.

Constraints at the API level

  • Every download checks on the server that the order is paid.
  • The price is set by DocFlow's server, from configuration.
  • DocFlow passes the person's own token to services when they are present, and a delegated token for them when not, so every service's ownership checks apply.
  • Service events are verified and processed once.