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

# Parse

> Turn a file into markdown, text, blocks, and optional chunks

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

const client = new NdiClient();
const upload = await client.documents.createUpload("report.pdf");
const job = await client.jobs.wait(
  (await client.documents.parse(upload, { wait_seconds: 30 })).job_id,
  { timeout: 600 },
);
if (isParseResult(job.result)) {
  console.log(job.result.markdown);
}
```

`ocr_applied` on the result says whether OCR ran.

## Method signature

```text theme={"dark"}
parse(
  source: DocumentSource | UploadResponse,
  opts?: {
    page_ranges?: PageRange[];
    quality?: "auto";
    ocr?: ParseOcrOptions;
    output?: ParseOutputOptions;
    figures?: ParseFiguresOptions;
    diagrams?: ParseDiagramsOptions;
    chunking?: ParseChunkingOptions;
    spreadsheet?: ParseSpreadsheetOptions;
    password?: string;
    wait_seconds?: number;
    idempotency_key?: string;
  },
): Promise<Job>
```

### Parameters

| Parameter              | Type                                 | Required | Description                                        |
| ---------------------- | ------------------------------------ | -------- | -------------------------------------------------- |
| `source`               | `DocumentSource` or `UploadResponse` | Yes      | Upload handle, URL, workspace file, or prior parse |
| `opts.page_ranges`     | `PageRange[]`                        | No       | Inclusive 1-indexed ranges                         |
| `opts.quality`         | `"auto"`                             | No       | Only accepted value                                |
| `opts.ocr`             | `ParseOcrOptions`                    | No       | `mode`: `auto` / `force` / `disabled`              |
| `opts.output`          | `ParseOutputOptions`                 | No       | `formats`, `table_format`, `include_images`        |
| `opts.figures`         | `ParseFiguresOptions`                | No       | Default `describe`; also `omit` / `include`        |
| `opts.diagrams`        | `ParseDiagramsOptions`               | No       | `omit` or `mermaid`                                |
| `opts.chunking`        | `ParseChunkingOptions`               | No       | `none` / `page` / `section`                        |
| `opts.spreadsheet`     | `ParseSpreadsheetOptions`            | No       | Sheet, row, and column filters                     |
| `opts.password`        | `string`                             | No       | Encrypted PDF; write-only                          |
| `opts.wait_seconds`    | `number`                             | No       | Hold the HTTP response open (max 300)              |
| `opts.idempotency_key` | `string`                             | No       | Override the minted header                         |

### Returns

A `Job`. Narrow with `isParseResult(job.result)`. `result.markdown` is a
convenience alias for `result.document.markdown`.

## Options

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

const client = new NdiClient();
const upload = await client.documents.createUpload("report.pdf");
const job = await client.jobs.wait(
  (
    await client.documents.parse(upload, {
      page_ranges: [{ start: 1, end: 1 }],
      output: { formats: ["markdown", "blocks"], table_format: "html" },
      chunking: { strategy: "page" },
      wait_seconds: 30,
    })
  ).job_id,
);
if (isParseResult(job.result)) {
  console.log(job.result.document.chunks?.length);
}
```

Reuse a parse with `{ type: "parse_result", job_id }`. Page selection and
`include_images` are not available on that source.

See [Parse guide](/guides/parse) and [Parse response](/guides/parse-response).
