# Parse

> Upload a PDF or Office file and get its text back. Nothing is fetched and nothing is stored.

`POST /v2/parse` reads a file you already hold, such as a PDF you saved earlier, and returns its text. Nothing is fetched, so Tor is not needed, and nothing is stored: no capture and no copy of the file. The reply is the only copy.

```bash
curl -X POST https://api.darkcrawl.dev/v2/parse \
  -H "Authorization: Bearer $DARKCRAWL_API_KEY" \
  -F "file=@<your file>" \
  -F 'options={"formats":["markdown","links"]}'
```

The request is `multipart/form-data` with a `file` part and, optionally, an `options` part that holds JSON. The sample sends the options as JSON, and `<your file>` stands for your own file.

```json
{
  "success": true,
  "data": {
    "markdown": "# Sample report\n\nPage one of a fictional PDF.\n",
    "indicators": [],
    "metadata": {
      "title": "Sample report",
      "numPages": 1,
      "totalPages": 1,
      "sourceFile": "report.pdf",
      "contentType": "application/pdf",
      "document": {
        "type": "pdf",
        "pages": 1,
        "totalPages": 1,
        "ocrPages": 0,
        "truncated": false,
        "encrypted": false
      }
    }
  }
}
```

## What is read

PDF and Office documents (DOCX, PPTX, XLSX and their macro-enabled forms) with the `pdf` parser, which is on by default. An image (PNG, JPEG, GIF, TIFF, BMP, WebP or JPEG 2000) is read by OCR only when `parsers` holds `"image"`. The file’s bytes decide its type, not its name. Anything else answers `422 EXTRACTION_FAILED` with `details.reason` set to `unsupported`.

Only the text parts of a document are read, in a sandbox. Embedded files, media and macros are never opened or run, and nothing the document refers to is fetched. `GET /v2/parse/formats` lists the extensions and MIME types it reads.

## Options

| Option      | What it does                                                                                                                                                                                                                                                                                                   |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `formats`   | `markdown` (the default) and `links`. `html` and `rawHtml` are left out with a warning. `attributes`, `product` and `changeTracking` need a fetched page and answer `400 NOT_IMPLEMENTED`. The model formats run on the document’s text and answer `503 AI_UNAVAILABLE` when the server has no model provider. |
| `timeout`   | Milliseconds, 1000 to 300000, 30000 by default. It covers the wait for a sandbox worker and the reading.                                                                                                                                                                                                       |
| `parsers`   | As on [scrape](https://darkcrawl.dev/docs/endpoints/scrape/): turn OCR on for scanned pages or images.                                                                                                                                                                                                         |
| `redactPII` | As on scrape.                                                                                                                                                                                                                                                                                                  |

`onlyMainContent`, `includeTags`, `excludeTags`, `mobile`, `blockAds` and `fastMode` are ignored, with a warning when they are not Firecrawl’s default. Any other field is `400 BAD_REQUEST`.

## Reply

`data` holds `markdown`, `links` when asked, `indicators` and `metadata`: `title`, `numPages`, `totalPages`, `sourceFile`, `contentType` and `document`. A file that cannot be read answers `422 EXTRACTION_FAILED` with a `details.reason` of `encrypted`, `malformed`, `too_large`, `ocr_unavailable` or `timeout`.

## Limits

A parse counts as one request. A file over the size limit answers `413 PAYLOAD_TOO_LARGE`, and when too many uploads are in progress at once a request answers `503 EXTRACTION_UNAVAILABLE` with `details.reason` set to `busy`: send it again later. The plan’s request limits and its upload size are on [Rate limits](https://darkcrawl.dev/docs/api-reference/rate-limits/).

## Reference

- [POST /v2/parse](https://darkcrawl.dev/docs/api-reference/parse/post-v2-parse/)
- [GET /v2/parse/formats](https://darkcrawl.dev/docs/api-reference/parse/get-v2-parse-formats/)
