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

# Classify

> Label one file against classes you define

Classify reads the original file. It rejects a `parse_result` source.

```ts theme={"dark"}
import { NdiClient } from "ndi-sdk";

const client = new NdiClient();
const document = await client.documents.createUpload("invoice.pdf");
const job = await client.jobs.wait(
  (
    await client.documents.classify(document, {
      classes: [{ id: "invoice", label: "Invoice", description: "A supplier invoice" }],
      wait_seconds: 30,
    })
  ).job_id,
);
if (job.result?.result_type === "classify" && "units" in job.result) {
  for (const unit of job.result.units) {
    console.log(unit.unknown, unit.labels);
  }
}
```

## Method signature

```text theme={"dark"}
classify(
  source: UploadSource | UrlSource | WorkspaceFileSource | UploadResponse,
  opts: {
    classes: ClassifyClass[];
    granularity?: "document" | "page";
    page_ranges?: PageRange[];
    unknown_policy?: "allow" | "force_best";
    output?: ClassifyOutputOptions;
    wait_seconds?: number;
    idempotency_key?: string;
  },
): Promise<Job>
```

### Parameters

| Parameter             | Type                        | Required | Description                           |
| --------------------- | --------------------------- | -------- | ------------------------------------- |
| `source`              | upload, URL, workspace file | Yes      | Original file — not a `parse_result`  |
| `opts.classes`        | `ClassifyClass[]`           | Yes      | Labels to choose from                 |
| `opts.granularity`    | `"document"` / `"page"`     | No       | Default `document`                    |
| `opts.page_ranges`    | `PageRange[]`               | No       | Inclusive 1-indexed ranges            |
| `opts.unknown_policy` | `"allow"` / `"force_best"`  | No       | Default `allow`                       |
| `opts.output`         | `ClassifyOutputOptions`     | No       | Alternatives and reasons              |
| `opts.wait_seconds`   | `number`                    | No       | Hold the HTTP response open (max 300) |

### Returns

A `Job`. On success, `result.units` is one row per document or page range.
Confidence is the fraction of the unit assigned that label, not a calibrated
probability.

See [Classify guide](/guides/classify).
