---
title: "Label documents, or find where each one starts"
---

> 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.

# Label documents, or find where each one starts

Path: CloudRaker Paperwork API › Capabilities

`POST /v1/classify`

Classify decides what a file is. [Split](https://docs.cloudraker.com/paperwork/capabilities/split) cuts it — they are two calls, and this is the only one that runs a model.

Send `classes`: at least two, each an `{id, description}`. The description is the accuracy lever — there is no training data — and the `id` is your branch key, returned untouched. One class is the catch-all; supply `{"id": "other", …}` or one is injected and echoed back in `config`.

**Two granularities:**

| `granularity` | Answer | Billed |
| --- | --- | --- |
| `document` (default) | one label for the whole file | the first and last window only |
| `page` | one label per page, plus derived `segments[]` | every page |

Page mode is what feeds split: the model marks the first page of each document, and contiguous, non-overlapping `segments[]` are derived from that in code — so two invoices back to back come back as two segments, not one. Pass the run id to [POST /v1/split](https://docs.cloudraker.com/paperwork/capabilities/split) as `classifyRunId`.

`confidence` is 0–5. A low score never rewrites the label: threshold it yourself, and re-run with a sharper `description` when the model is unsure.

```json
{
  "file": { "url": "https://acme.example/scans/mail.pdf" },
  "classes": [
    { "id": "invoice", "description": "A bill from a supplier with line items and a total due." },
    { "id": "contract", "description": "A signed agreement with clauses and signature blocks." }
  ],
  "granularity": "page"
}
```

### 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:** [Classification guide](https://docs.cloudraker.com/paperwork/capabilities/classify)

## Authentication

- `bearerAuth`, http, header `Authorization`

## Query parameters

- `wait` (`classify.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`

## Request body

_Required._

- `classes` (`classify.classes`; array<object>, optional) — The classes to choose from, at least 2 and at most 50. Required unless you name a saved `action` that carries them. One class is the catch-all. Supply one with `id: "other"`, or one is injected for you and echoed back on the run — a closed set with no exit makes the model guess.
  - `id` (`classify.classes.id`; string, required)
    - pattern `^[a-z0-9][a-z0-9_-]{0,63}$`; example `"invoice"`
  - `description` (`classify.classes.description`; string, required)
    - minLength 1; maxLength 500; example `"A bill from a supplier listing line items, quantities and a total amount due."`
- `granularity` (`classify.granularity`; string, optional) — What one label covers. `document` (the default) answers once for the whole file and bills only the pages sent to the model; `page` answers per page, derives `segments[]` from where documents start, and bills every page.
  - one of `"document"`, `"page"`
- `rules` (`classify.rules`; object, optional) — Page mode only. A segment shorter than `minPages` (default 1) merges into its neighbour.
  - `minPages` (`classify.rules.minPages`; integer, optional)
    - min 1; max 750
- `instructions` (`classify.instructions`; string, optional) — Free-form guidance applied on top of the class descriptions — how to treat continuation sheets, which class wins a tie.
  - maxLength 4000
- `pageRange` (`classify.pageRange`; object, optional) — The pages to consider, 1-based inclusive. Defaults to the first 750 pages, which is also the maximum — a wider range is a `page_limit_exceeded` error, never a silent truncation.
  - `start` (`classify.pageRange.start`; integer, required)
    - min 1; max 9007199254740991
  - `end` (`classify.pageRange.end`; integer, required)
    - min 1; max 9007199254740991
- `action` (`classify.action`; string, optional) — A saved classify config to run, by id or slug. Config you send inline is merged over it.
  - minLength 1
- `file` (`classify.file`; any of, optional) — An input file, given one of two ways. - `{ "url": "…", "name"?: "…", "processing"?: "…" }` — fetched over http(s) for this run and purged with it. - `{ "id": "…" }` — a file you already registered with `POST /v1/files`, reusable across runs and never re-parsed. - `{ "id": "…", "ephemeral": true }` — a file you uploaded only for this run, purged with it. Use it only on a file no other run uses.
  - any of:
    - `object`
      - `url` (`classify.file.1.url`; string, required)
        - format `uri`
      - `name` (`classify.file.1.name`; string, optional)
        - minLength 1
      - `processing` (`classify.file.1.processing`; string, optional)
        - one of `"auto"`, `"ocr"`, `"simple"`, `"transcribe"`, `"transcribe_diarize"`
    - `object`
      - `id` (`classify.file.2.id`; string, required)
        - minLength 1
      - `ephemeral` (`classify.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` (`classify.files`; array<any of>, optional)
  - any of:
    - `object`
      - `url` (`classify.files.1.url`; string, required)
        - format `uri`
      - `name` (`classify.files.1.name`; string, optional)
        - minLength 1
      - `processing` (`classify.files.1.processing`; string, optional)
        - one of `"auto"`, `"ocr"`, `"simple"`, `"transcribe"`, `"transcribe_diarize"`
    - `object`
      - `id` (`classify.files.2.id`; string, required)
        - minLength 1
      - `ephemeral` (`classify.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` (`classify.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` (`classify.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` (`classify.webhook.1.url`; string, required)
        - format `uri`
    - `object`
      - `id` (`classify.webhook.2.id`; string, required)
        - minLength 1
- `ttl` (`classify.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
{
  "classes": [
    {
      "id": "invoice",
      "description": "A bill from a supplier listing line items, quantities and a total amount due."
    }
  ],
  "granularity": "document",
  "rules": {
    "minPages": 1
  },
  "instructions": "string",
  "pageRange": {
    "start": 1,
    "end": 1
  },
  "action": "string",
  "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/classify \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "classes": [
    {
      "id": "invoice",
      "description": "A bill from a supplier listing line items, quantities and a total amount due."
    }
  ],
  "granularity": "document",
  "rules": {
    "minPages": 1
  },
  "instructions": "string",
  "pageRange": {
    "start": 1,
    "end": 1
  },
  "action": "string",
  "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/classify';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    classes: [
      {
        id: 'invoice',
        description: 'A bill from a supplier listing line items, quantities and a total amount due.'
      }
    ],
    granularity: 'document',
    rules: {minPages: 1},
    instructions: 'string',
    pageRange: {start: 1, end: 1},
    action: 'string',
    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/classify"

payload = {
    "classes": [
        {
            "id": "invoice",
            "description": "A bill from a supplier listing line items, quantities and a total amount due."
        }
    ],
    "granularity": "document",
    "rules": { "minPages": 1 },
    "instructions": "string",
    "pageRange": {
        "start": 1,
        "end": 1
    },
    "action": "string",
    "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": "classify_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": {
    "classes": [
      {
        "id": "invoice",
        "description": "A bill from a supplier listing line items, quantities and a total amount due."
      }
    ],
    "granularity": "document",
    "rules": {
      "minPages": 0
    }
  },
  "usage": {
    "pages": 0,
    "parse": 0,
    "split": 0
  },
  "output": {
    "granularity": "document",
    "classId": "string",
    "confidence": 0,
    "reasoning": "string",
    "documents": [
      {
        "fileId": "string",
        "status": "string",
        "error": "string",
        "classId": "string",
        "confidence": 0,
        "reasoning": "string"
      }
    ],
    "pages": [
      {
        "page": 0,
        "classId": "string",
        "documentStart": true,
        "confidence": 0,
        "reasoning": "string"
      }
    ],
    "segments": [
      {
        "startPage": 0,
        "endPage": 0,
        "classId": "string",
        "confidence": 0
      }
    ],
    "unassignedPages": [
      0
    ]
  }
}
```

- `object` (`classify.response.200.object`; string, required)
- `id` (`classify.response.200.id`; string, required)
- `status` (`classify.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` (`classify.response.200.expiresAt`; string | null, required)
- `statusUrl` (`classify.response.200.statusUrl`; string, required)
- `files` (`classify.response.200.files`; array<object>, required)
  - `id` (`classify.response.200.files.id`; string, required)
  - `name` (`classify.response.200.files.name`; string, required)
  - `status` (`classify.response.200.files.status`; string, required)
  - `error` (`classify.response.200.files.error`; string, optional)
- `file` (`classify.response.200.file`; object, optional)
  - `id` (`classify.response.200.file.id`; string, required)
  - `name` (`classify.response.200.file.name`; string, required)
  - `status` (`classify.response.200.file.status`; string, required)
  - `error` (`classify.response.200.file.error`; string, optional)
- `error` (`classify.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` (`classify.response.200.error.code`; string, required)
  - `message` (`classify.response.200.error.message`; string, required)
- `metadata` (`classify.response.200.metadata`; map<unknown>, optional)
- `config` (`classify.response.200.config`; object, optional)
  - `classes` (`classify.response.200.config.classes`; array<object>, optional)
    - `id` (`classify.response.200.config.classes.id`; string, required)
      - pattern `^[a-z0-9][a-z0-9_-]{0,63}$`; example `"invoice"`
    - `description` (`classify.response.200.config.classes.description`; string, required)
      - minLength 1; maxLength 500; example `"A bill from a supplier listing line items, quantities and a total amount due."`
  - `granularity` (`classify.response.200.config.granularity`; string, optional) — What one label covers. `document` (the default) answers once for the whole file and bills only the pages sent to the model; `page` answers per page, derives `segments[]` from where documents start, and bills every page.
    - one of `"document"`, `"page"`
  - `rules` (`classify.response.200.config.rules`; object, optional)
    - `minPages` (`classify.response.200.config.rules.minPages`; number, optional)
- `usage` (`classify.response.200.usage`; object, optional)
  - `pages` (`classify.response.200.usage.pages`; number, optional)
  - `parse` (`classify.response.200.usage.parse`; number, optional)
  - `split` (`classify.response.200.usage.split`; number, optional)
- `output` (`classify.response.200.output`; object, optional) — The labels. Present once `status` is `processed`. In document mode `classId`, `confidence` and `reasoning` are the first document's, and `documents[]` is authoritative for a multi-file run. In page mode `pages[]` is the raw per-page answer and `segments[]` is what `POST /v1/split` consumes.
  - `granularity` (`classify.response.200.output.granularity`; string, optional) — What one label covers. `document` (the default) answers once for the whole file and bills only the pages sent to the model; `page` answers per page, derives `segments[]` from where documents start, and bills every page.
    - one of `"document"`, `"page"`
  - `classId` (`classify.response.200.output.classId`; string, optional)
  - `confidence` (`classify.response.200.output.confidence`; number, optional) — How sure the model was, 0–5. Route below 4 to a human; the label itself is never rewritten by a threshold.
  - `reasoning` (`classify.response.200.output.reasoning`; string, optional)
  - `documents` (`classify.response.200.output.documents`; array<object>, optional)
    - `fileId` (`classify.response.200.output.documents.fileId`; string, required)
    - `status` (`classify.response.200.output.documents.status`; string, optional)
    - `error` (`classify.response.200.output.documents.error`; string, optional)
    - `classId` (`classify.response.200.output.documents.classId`; string, optional)
    - `confidence` (`classify.response.200.output.documents.confidence`; number, optional) — How sure the model was, 0–5. Route below 4 to a human; the label itself is never rewritten by a threshold.
    - `reasoning` (`classify.response.200.output.documents.reasoning`; string, optional)
  - `pages` (`classify.response.200.output.pages`; array<object>, optional)
    - `page` (`classify.response.200.output.pages.page`; number, required)
    - `classId` (`classify.response.200.output.pages.classId`; string, required)
    - `documentStart` (`classify.response.200.output.pages.documentStart`; boolean, optional)
    - `confidence` (`classify.response.200.output.pages.confidence`; number, optional) — How sure the model was, 0–5. Route below 4 to a human; the label itself is never rewritten by a threshold.
    - `reasoning` (`classify.response.200.output.pages.reasoning`; string, optional)
  - `segments` (`classify.response.200.output.segments`; array<object>, optional)
    - `startPage` (`classify.response.200.output.segments.startPage`; number, required)
    - `endPage` (`classify.response.200.output.segments.endPage`; number, required)
    - `classId` (`classify.response.200.output.segments.classId`; string, optional)
    - `confidence` (`classify.response.200.output.segments.confidence`; number, optional) — How sure the model was, 0–5. Route below 4 to a human; the label itself is never rewritten by a threshold.
  - `unassignedPages` (`classify.response.200.output.unassignedPages`; array<number>, optional)

### 202

Accepted — still running, or awaiting human input.

#### Example

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

- `object` (`classify.response.202.object`; string, required)
- `id` (`classify.response.202.id`; string, required)
- `status` (`classify.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` (`classify.response.202.statusUrl`; string, required)
- `envelopeUrl` (`classify.response.202.envelopeUrl`; string, optional)

### 400

Invalid request (`classes_required`, `duplicate_class_id`, `too_many_classes`, `config_too_large`, `page_limit_exceeded`, `capability_mismatch`).

### 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` (`classify.response.429.code`; string, required)
  - one of `"rate_limited"`
- `message` (`classify.response.429.message`; string, required)
- `retryable` (`classify.response.429.retryable`; boolean, required)
  - one of `true`
- `requestId` (`classify.response.429.requestId`; string, required)
- `docUrl` (`classify.response.429.docUrl`; string, optional)


Source: https://docs.cloudraker.com/paperwork/api/capabilities/classify/index.md
