---
title: "Extract structured data from documents"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Extract structured data from documents

Path: CloudRaker Paperwork API › Spaces

`POST /v1/spaces/{spaceId}/extract`

Runs JSON-Schema extraction with per-field citations over one or more files.

Send exactly one of `file` or `files`, and at most one output shape:

- **`schema`** — an inline JSON Schema object, written in the [extraction schema dialect](https://docs.cloudraker.com/paperwork/capabilities/extract/schema).
- **`action`** — a [saved action](https://docs.cloudraker.com/paperwork/api/actions/get-action) by id or slug. Inline config fields (`instructions`, `unit`, `judge`, …) are merged over the saved action's, so one saved action can be refined per call.
- **neither** — the shape is inferred from the documents themselves. Add `hints` to steer it in prose. The finished run reports what was inferred as `config.schema`, ready to save as an action for the next run.

**What you get back.** `output.value` holds the extracted object for a single-document run, `output.documents[]` one entry per file. Send `citations: true` to ground the result: `output.citations` then maps each extracted field to where it came from — `fileId` plus page and bounding box, or `timecodeStart`/`timecodeEnd` for audio, or `notFound: true` for a value the documents do not contain.

Add `?output=inline` to include each source file's parsed `markdown` and `json` alongside the extracted value. Signed `markdownUrl` / `jsonUrl` fields remain available; when the combined parsed source exceeds 1 MiB, the response falls back to those URLs only.

```json
{
  "file": { "url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf" },
  "schema": {
    "type": "object",
    "properties": {
      "business_name": { "type": ["string", "null"] },
      "tax_classification": { "type": ["string", "null"] }
    }
  }
}
```

### Waiting for the result

Sync by default: the call holds open until the run finishes, up to `?wait=` seconds (default `60`, max `120`, `0` returns immediately).

| Outcome | Response |
| --- | --- |
| Finished inside the window | `200` with the full run |
| Still running at the cap | `202` with `{object, id, status, statusUrl}` |

> **Note:** The `202` is a graceful degrade, never an error — poll [the run](https://docs.cloudraker.com/paperwork/api/runs/get-run) or wait for a [webhook](https://docs.cloudraker.com/paperwork/api/webhook-endpoints/create-webhook-endpoint). Replaying an `idempotency-key` returns the original run alongside an `idempotent-replay: true` response header.

**Learn more:** [Extraction guide](https://docs.cloudraker.com/paperwork/capabilities/extract) · [Schema dialect](https://docs.cloudraker.com/paperwork/capabilities/extract/schema)

## Authentication

- `bearerAuth`, http, header `Authorization`

## Path parameters

- `spaceId` (`spaceExtract.path.spaceId`; string, required)

## Query parameters

- `wait` (`spaceExtract.query.wait`; integer, optional) — How many seconds to hold the request open waiting for the run to finish. Finishing inside the window returns `200` with the full run; running past it returns `202` with a `statusUrl` to poll. Send `0` to skip waiting entirely and always get the `202`.
  - min 0; max 120; default `60`
- `output` (`spaceExtract.query.output`; string, optional) — How parsed source content is returned. `urls` returns signed download URLs. `inline` also returns markdown and parsed JSON when their combined payload is at most 1 MiB; larger content falls back to the URLs only.
  - one of `"urls"`, `"inline"`; default `"urls"`

## Request body

_Required._

- `schema` (`spaceExtract.schema`; map<unknown>, optional) — The shape to extract, as a JSON Schema object. Send `action` instead to use a saved shape, or neither to have one inferred. The root must be `{"type": "object"}`. The dialect is deliberately narrow — no `$ref`, `$defs`, `oneOf`, `anyOf`, `allOf`, `const` or `pattern` — with a maximum nesting depth of 5 and a 64 KB size limit. Make primitives nullable (`{"type": ["string", "null"]}`) so a missing value reads as `null` rather than a hallucination.
- `action` (`spaceExtract.action`; string, optional) — A saved action to run, by id or slug. An alternative to `schema`. The action carries the output shape and any saved settings. Config you send inline on the same call is merged over it, so `action` plus `instructions` refines a saved action for one run without redefining it.
  - minLength 1; example `"act_01JQ8ZKMRT4V6WXYZ0ABCDEFGH"`
- `hints` (`spaceExtract.hints`; string, optional) — Prose guidance for **schema inference** — only valid when you send neither `schema` nor `action`. Say what the documents are and what matters in them ("freight bills of lading; I care about the load number, the shipper and the total") and the shape is inferred from the document itself. Sending `hints` alongside `schema` or `action` is a `400`: the shape is already decided.
  - maxLength 2000
- `instructions` (`spaceExtract.instructions`; string, optional) — Free-form guidance for the extraction, applied on top of the schema — house rules, formatting preferences, how to handle ambiguity.
- `citations` (`spaceExtract.citations`; boolean, optional) — Whether to ground each extracted value in the source document. Off by default — grounding is an explicit add-on, so send `citations: true` to ask for it. When on, `output.citations` maps every extracted field to where it came from — `fileId` plus page and bounding box for documents, or `timecodeStart`/`timecodeEnd` for audio. A field the documents simply do not contain comes back as an entry with `notFound: true` and no location.
- `unit` (`spaceExtract.unit`; string, optional) — What one extraction result covers. - `per_document`: one result object per file (the default). - `across_documents`: one result object for the whole set. The files are read together as one source, in the order you list them, so a recording split into parts reads as one recording. Audio mixed with documents cannot be read as one source: each file is then extracted on its own and the results are merged. - `rows_per_document`: a list of results per file, for documents that hold repeated records.
  - one of `"per_document"`, `"across_documents"`, `"rows_per_document"`
- `judge` (`spaceExtract.judge`; boolean, optional) — Run a second review pass that scores each extracted value against the evidence it cites, adding a `confidence` (0–5) and leaving the values themselves alone. **It is the only pass that scores**: grounding cites without grading, so an unjudged run returns citations with no `confidence`. Slower and more thorough; worth it on documents where an error is expensive. **The judge audits citations, so it needs `citations: true`.** It scores cited evidence and never re-extracts, so with grounding off there is nothing for it to audit. Sending `judge: true` with `citations: false` is a `400`. When you name an `action`, the saved config's `citations` setting counts — a judge on a saved action that does not ground does nothing.
- `file` (`spaceExtract.file`; any of, optional) — A single input file. Send this or `files`, never both.
  - any of:
    - `object`
      - `url` (`spaceExtract.file.1.url`; string, required)
        - format `uri`
      - `name` (`spaceExtract.file.1.name`; string, optional)
        - minLength 1
      - `processing` (`spaceExtract.file.1.processing`; string, optional)
        - one of `"auto"`, `"ocr"`, `"simple"`, `"transcribe"`, `"transcribe_diarize"`
    - `object`
      - `id` (`spaceExtract.file.2.id`; string, required)
        - minLength 1
      - `ephemeral` (`spaceExtract.file.2.ephemeral`; boolean, optional) — Purge this file with the run (TTL expiry or `DELETE /v1/runs/{id}`), unless you `keep` the run. API workspace only: ignored under `/v1/spaces/{spaceId}/…`.
- `files` (`spaceExtract.files`; array<any of>, optional) — Several input files, up to 100. Send this or `file`, never both. Each file gets its own entry in `output.documents[]` unless `unit` says otherwise.
  - any of:
    - `object`
      - `url` (`spaceExtract.files.1.url`; string, required)
        - format `uri`
      - `name` (`spaceExtract.files.1.name`; string, optional)
        - minLength 1
      - `processing` (`spaceExtract.files.1.processing`; string, optional)
        - one of `"auto"`, `"ocr"`, `"simple"`, `"transcribe"`, `"transcribe_diarize"`
    - `object`
      - `id` (`spaceExtract.files.2.id`; string, required)
        - minLength 1
      - `ephemeral` (`spaceExtract.files.2.ephemeral`; boolean, optional) — Purge this file with the run (TTL expiry or `DELETE /v1/runs/{id}`), unless you `keep` the run. API workspace only: ignored under `/v1/spaces/{spaceId}/…`.
- `metadata` (`spaceExtract.metadata`; map<unknown>, optional) — Arbitrary JSON you attach to the run and get back on every read of it. Use it to carry your own identifiers — an order number, a customer id — so a webhook or a polled run reconciles without a lookup table. Capped at 10 KB serialized.
- `webhook` (`spaceExtract.webhook`; any of, optional) — Where to deliver this run's events, given one of two ways. - `{ "url": "…" }` — a one-off https endpoint for this run only. - `{ "id": "whe_…" }` — a saved endpoint from `POST /v1/webhooks`. Runs hold the reference, so pausing or re-pointing that endpoint applies to this run too. Deliveries are at-least-once and signed — dedupe on `eventId` and verify against `GET /v1/webhooks/jwks.json`.
  - any of:
    - `object`
      - `url` (`spaceExtract.webhook.1.url`; string, required)
        - format `uri`
    - `object`
      - `id` (`spaceExtract.webhook.2.id`; string, required)
        - minLength 1
- `ttl` (`spaceExtract.ttl`; integer, optional) — How long, in seconds, to keep this run and its files before purging them automatically. The maximum is 604800 (7 days). The deadline comes back as `expiresAt` on every read of the run. Call `POST /v1/runs/{id}/keep` before then to clear the TTL and move the results into a space permanently. E-signature runs are exempt — an envelope waits for its signers however long that takes.
  - min 1; max 604800; default `86400`

## Example request

```json
{
  "schema": {
    "property1": null,
    "property2": null
  },
  "action": "act_01JQ8ZKMRT4V6WXYZ0ABCDEFGH",
  "hints": "string",
  "instructions": "string",
  "citations": true,
  "unit": "per_document",
  "judge": true,
  "file": {
    "url": "http://example.com",
    "name": "string",
    "processing": "auto"
  },
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "processing": "auto"
    }
  ],
  "metadata": {
    "property1": null,
    "property2": null
  },
  "webhook": {
    "url": "http://example.com"
  },
  "ttl": 86400
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.cloudraker.com/v1/spaces/<spaceId>/extract' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "schema": {
    "property1": null,
    "property2": null
  },
  "action": "act_01JQ8ZKMRT4V6WXYZ0ABCDEFGH",
  "hints": "string",
  "instructions": "string",
  "citations": true,
  "unit": "per_document",
  "judge": true,
  "file": {
    "url": "http://example.com",
    "name": "string",
    "processing": "auto"
  },
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "processing": "auto"
    }
  ],
  "metadata": {
    "property1": null,
    "property2": null
  },
  "webhook": {
    "url": "http://example.com"
  },
  "ttl": 86400
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/v1/spaces/<spaceId>/extract';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    schema: {property1: null, property2: null},
    action: 'act_01JQ8ZKMRT4V6WXYZ0ABCDEFGH',
    hints: 'string',
    instructions: 'string',
    citations: true,
    unit: 'per_document',
    judge: true,
    file: {url: 'http://example.com', name: 'string', processing: 'auto'},
    files: [{url: 'http://example.com', name: 'string', processing: 'auto'}],
    metadata: {property1: null, property2: null},
    webhook: {url: 'http://example.com'},
    ttl: 86400
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/v1/spaces/<spaceId>/extract"

payload = {
    "schema": {
        "property1": None,
        "property2": None
    },
    "action": "act_01JQ8ZKMRT4V6WXYZ0ABCDEFGH",
    "hints": "string",
    "instructions": "string",
    "citations": True,
    "unit": "per_document",
    "judge": True,
    "file": {
        "url": "http://example.com",
        "name": "string",
        "processing": "auto"
    },
    "files": [
        {
            "url": "http://example.com",
            "name": "string",
            "processing": "auto"
        }
    ],
    "metadata": {
        "property1": None,
        "property2": None
    },
    "webhook": { "url": "http://example.com" },
    "ttl": 86400
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The finished run.

#### Example

```json
{
  "object": "extract_run",
  "id": "string",
  "status": "queued",
  "expiresAt": "string",
  "statusUrl": "string",
  "files": [
    {
      "id": "string",
      "name": "string",
      "status": "string",
      "error": "string"
    }
  ],
  "file": {
    "id": "string",
    "name": "string",
    "status": "string",
    "error": "string"
  },
  "error": {
    "code": "string",
    "message": "string"
  },
  "metadata": {
    "property1": null,
    "property2": null
  },
  "config": {
    "schema": {
      "property1": null,
      "property2": null
    },
    "revision": 1,
    "overridden": true
  },
  "output": {
    "value": null,
    "citations": {
      "property1": [
        {
          "fileId": "string",
          "page": 0,
          "bbox": {
            "x": 0,
            "y": 0,
            "width": 0,
            "height": 0
          },
          "timecodeStart": 0,
          "timecodeEnd": 0,
          "timecode": 0,
          "text": "string",
          "confidence": 0,
          "uncited": true,
          "notFound": true
        }
      ],
      "property2": [
        {
          "fileId": "string",
          "page": 0,
          "bbox": {
            "x": 0,
            "y": 0,
            "width": 0,
            "height": 0
          },
          "timecodeStart": 0,
          "timecodeEnd": 0,
          "timecode": 0,
          "text": "string",
          "confidence": 0,
          "uncited": true,
          "notFound": true
        }
      ]
    },
    "citationsOmitted": true,
    "markdownUrl": "string",
    "jsonUrl": "string",
    "markdown": "string",
    "json": null,
    "documents": [
      {
        "fileId": "string",
        "name": "string",
        "status": "string",
        "error": "string",
        "value": null,
        "citations": {
          "property1": [
            {
              "fileId": "string",
              "page": 0,
              "bbox": {},
              "timecodeStart": 0,
              "timecodeEnd": 0,
              "timecode": 0,
              "text": "string",
              "confidence": 0,
              "uncited": true,
              "notFound": true
            }
          ],
          "property2": [
            {
              "fileId": "string",
              "page": 0,
              "bbox": {},
              "timecodeStart": 0,
              "timecodeEnd": 0,
              "timecode": 0,
              "text": "string",
              "confidence": 0,
              "uncited": true,
              "notFound": true
            }
          ]
        },
        "markdownUrl": "string",
        "jsonUrl": "string",
        "markdown": "string",
        "json": null
      }
    ]
  }
}
```

- `object` (`spaceExtract.response.200.object`; string, required)
- `id` (`spaceExtract.response.200.id`; string, required)
- `status` (`spaceExtract.response.200.status`; string, required) — Where the run is in its life. | Status | Meaning | | --- | --- | | `queued` | Accepted, not started | | `processing` | Work in flight | | `needs_input` | Waiting for an external action, such as an e-signature | | `processed` | Finished; `output` is populated | | `failed` | Finished unsuccessfully | | `cancelled` | Stopped on request | | `expired` | TTL elapsed and the data was purged | The last four are terminal.
  - one of `"queued"`, `"processing"`, `"processed"`, `"failed"`, `"cancelled"`, `"expired"`, `"needs_input"`
- `expiresAt` (`spaceExtract.response.200.expiresAt`; string | null, required)
- `statusUrl` (`spaceExtract.response.200.statusUrl`; string, required)
- `files` (`spaceExtract.response.200.files`; array<object>, required)
  - `id` (`spaceExtract.response.200.files.id`; string, required)
  - `name` (`spaceExtract.response.200.files.name`; string, required)
  - `status` (`spaceExtract.response.200.files.status`; string, required)
  - `error` (`spaceExtract.response.200.files.error`; string, optional)
- `file` (`spaceExtract.response.200.file`; object, optional)
  - `id` (`spaceExtract.response.200.file.id`; string, required)
  - `name` (`spaceExtract.response.200.file.name`; string, required)
  - `status` (`spaceExtract.response.200.file.status`; string, required)
  - `error` (`spaceExtract.response.200.file.error`; string, optional)
- `error` (`spaceExtract.response.200.error`; object, optional) — Why the run failed. Present whenever `status` is `failed`, and only then. `code` is the stable, snake_case reason (`input_unavailable`, `parse_failed`, …); `message` is the human-readable detail. Per-file and per-step failures are also reported in `files[].error` and, for a pipeline, `steps[].error`.
  - `code` (`spaceExtract.response.200.error.code`; string, required)
  - `message` (`spaceExtract.response.200.error.message`; string, required)
- `metadata` (`spaceExtract.response.200.metadata`; map<unknown>, optional)
- `config` (`spaceExtract.response.200.config`; object, optional) — The output shape this run actually applied. On an inference run — one sent with neither `schema` nor `action` — this is where you read the schema that was inferred, ready to review and save as an action for the next run.
  - `schema` (`spaceExtract.response.200.config.schema`; map<unknown>, required)
  - `revision` (`spaceExtract.response.200.config.revision`; integer, optional) — The revision of the saved config the run used. Each save that changes a config adds one. Absent on a run without a saved config, or one created before revisions existed.
    - min 1; max 9007199254740991
  - `overridden` (`spaceExtract.response.200.config.overridden`; boolean, optional) — True when inline config on the call changed the saved config for this run. Present with `revision`.
- `output` (`spaceExtract.response.200.output`; object, optional) — The extracted data. Present once `status` is `processed`. `documents[]` always has one entry per input file. For a single-document run, `value`, `citations` and any parsed source fields are lifted to the top as aliases of `documents[0]` so the common case reads without indexing. Parsed source fields are present only when requested with `?output=inline`. The signed URLs remain as a fallback; `markdown` and `json` are omitted when the combined inline source exceeds 1 MiB.
  - `documents` (`spaceExtract.response.200.output.documents`; array<object>, required)
    - `fileId` (`spaceExtract.response.200.output.documents.fileId`; string, required)
    - `name` (`spaceExtract.response.200.output.documents.name`; string, required)
    - `status` (`spaceExtract.response.200.output.documents.status`; string, required)
    - `error` (`spaceExtract.response.200.output.documents.error`; string, optional)
    - `value` (`spaceExtract.response.200.output.documents.value`; unknown, optional)
    - `citations` (`spaceExtract.response.200.output.documents.citations`; map<array<object>>, optional) — Where each extracted value came from, keyed by the field it backs. Keys are the top-level field keys of `value` (`load_number`); for a `rows_per_document` run they are prefixed with the row index, `[0].description`. Each entry names the `fileId` and, when known, the `page` and `bbox` (or `timecodeStart` and `timecodeEnd` for audio), plus the matched `text`. Add `judge: true` to also get a `confidence` score on each entry. An entry with `notFound: true` instead records that the value is not present in the documents at all, and the field is `null`; one with `uncited: true` records that the field IS filled but nothing in the source backs the value. Present whenever the run was grounded. Send `citations: true` on the request to ask for it.
    - `markdownUrl` (`spaceExtract.response.200.output.documents.markdownUrl`; string, optional)
    - `jsonUrl` (`spaceExtract.response.200.output.documents.jsonUrl`; string, optional)
    - `markdown` (`spaceExtract.response.200.output.documents.markdown`; string, optional)
    - `json` (`spaceExtract.response.200.output.documents.json`; unknown, optional)
  - `value` (`spaceExtract.response.200.output.value`; unknown, optional)
  - `citations` (`spaceExtract.response.200.output.citations`; map<array<object>>, optional) — Where each extracted value came from, keyed by the field it backs. Keys are the top-level field keys of `value` (`load_number`); for a `rows_per_document` run they are prefixed with the row index, `[0].description`. Each entry names the `fileId` and, when known, the `page` and `bbox` (or `timecodeStart` and `timecodeEnd` for audio), plus the matched `text`. Add `judge: true` to also get a `confidence` score on each entry. An entry with `notFound: true` instead records that the value is not present in the documents at all, and the field is `null`; one with `uncited: true` records that the field IS filled but nothing in the source backs the value. Present whenever the run was grounded. Send `citations: true` on the request to ask for it.
  - `citationsOmitted` (`spaceExtract.response.200.output.citationsOmitted`; boolean, optional) — The citations were dropped because the result exceeded the size budget.
  - `markdownUrl` (`spaceExtract.response.200.output.markdownUrl`; string, optional)
  - `jsonUrl` (`spaceExtract.response.200.output.jsonUrl`; string, optional)
  - `markdown` (`spaceExtract.response.200.output.markdown`; string, optional)
  - `json` (`spaceExtract.response.200.output.json`; unknown, optional)

### 202

Accepted — still running, or awaiting human input.

#### Example

```json
{
  "object": "string",
  "id": "string",
  "status": "queued",
  "statusUrl": "string",
  "envelopeUrl": "string"
}
```

- `object` (`spaceExtract.response.202.object`; string, required)
- `id` (`spaceExtract.response.202.id`; string, required)
- `status` (`spaceExtract.response.202.status`; string, required) — Where the run is in its life. | Status | Meaning | | --- | --- | | `queued` | Accepted, not started | | `processing` | Work in flight | | `needs_input` | Waiting for an external action, such as an e-signature | | `processed` | Finished; `output` is populated | | `failed` | Finished unsuccessfully | | `cancelled` | Stopped on request | | `expired` | TTL elapsed and the data was purged | The last four are terminal.
  - one of `"queued"`, `"processing"`, `"processed"`, `"failed"`, `"cancelled"`, `"expired"`, `"needs_input"`
- `statusUrl` (`spaceExtract.response.202.statusUrl`; string, required)
- `envelopeUrl` (`spaceExtract.response.202.envelopeUrl`; string, optional)

### 400

Invalid request (`invalid_request` / `invalid_schema`).

### 422

Unusable input file or webhook endpoint.

### 429

Rate limited. The `/v1` API allows at least **67 requests per minute per organization** (about 1,000 requests per 15 minutes) — a guaranteed floor, enforced per edge location, so a geographically spread caller may get more. Wait for the `Retry-After` interval and retry — the error is `retryable`.

#### Example

```json
{
  "code": "rate_limited",
  "message": "string",
  "retryable": true,
  "requestId": "string",
  "docUrl": "string"
}
```

- `code` (`spaceExtract.response.429.code`; string, required)
  - one of `"rate_limited"`
- `message` (`spaceExtract.response.429.message`; string, required)
- `retryable` (`spaceExtract.response.429.retryable`; boolean, required)
  - one of `true`
- `requestId` (`spaceExtract.response.429.requestId`; string, required)
- `docUrl` (`spaceExtract.response.429.docUrl`; string, optional)


Source: https://docs.cloudraker.com/paperwork/api/spaces/space-extract/index.md
