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

# Read a document

> A document's full text, one page range at a time

Returns the text of one document, by the `document_id` a [search](/api-reference/v3/search) result carries. Pages are numbered from 1. A response holds up to 100 pages or 2 MB of text, whichever comes first. `next_page_from` says where to continue.

## Path parameters

<ParamField path="document_id" type="string" required>
  The `document_id` of a search result. It is opaque: take it from a search,
  don't build it.
</ParamField>

## Query parameters

<ParamField query="page_from" type="integer" default={1}>
  First page to return. The first page is 1.
</ParamField>

<ParamField query="page_to" type="integer">
  Last page to return, inclusive. Omit to read to the end of the document, up to
  the 100-page or 2 MB cap.
</ParamField>

## Response

<ResponseField name="document_id" type="string">
  The document id.
</ResponseField>

<ResponseField name="dataset" type="string">
  The dataset id.
</ResponseField>

<ResponseField name="title" type="string">
  The document's title.
</ResponseField>

<ResponseField name="url" type="string">
  Link to the source document.
</ResponseField>

<ResponseField name="total_pages" type="integer">
  Pages in the document, so also the last page's `page_num`.
</ResponseField>

<ResponseField name="pages" type="array">
  The pages in the range, in order. Empty when the range starts past the last
  page.

  <Expandable title="Page object">
    <ResponseField name="page_num" type="integer">
      Page number. The first page is 1.
    </ResponseField>

    <ResponseField name="text" type="string">
      The full text of the page.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="next_page_from" type="integer | null">
  The page after the ones returned: send it as `page_from` to continue. `null`
  when the document ends there.
</ResponseField>

## Reading a whole document

```python Python theme={null}
import requests

document_id = "WyJmZGFfNDgzIixbImh0dHBzOi8vd3d3LmZkYS5nb3YvbWVkaWEvMDAwMDAwL2Rvd25sb2FkIl1d"
pages, page_from = [], 1
while page_from is not None:
    response = requests.get(
        f"https://rhizomeai.com/api/v3/documents/{document_id}",
        headers={"x-api-key": "YOUR_API_KEY"},
        params={"page_from": page_from},
    )
    response.raise_for_status()
    data = response.json()
    pages.extend(data["pages"])
    page_from = data["next_page_from"]

print(f"{data['title']}: {len(pages)} of {data['total_pages']} pages")
```

## Errors

Errors return `{"error": {"code", "message", "field", "request_id"}}`; `field` names the value at fault when there is one. See [Errors](/errors).

| Status | Code | Description |
| - | - | - |
| 400 | `invalid_request` | `page_from` or `page_to` isn't a positive integer (`0` included: pages start at 1), or `page_to` is before `page_from` |
| 401 | `missing_api_key`, `invalid_api_key` | Missing or invalid API key |
| 403 | `forbidden` | The document's dataset needs an enterprise plan |
| 404 | `not_found` | No document has this id |
| 429 | `rate_limited` | Rate limit exceeded (50 requests/minute) |
| 504 | `timeout` | Reading the document timed out |

<RequestExample>
  ```bash cURL theme={null}
  curl "https://rhizomeai.com/api/v3/documents/WyJmZGFfNDgzIixbImh0dHBzOi8vd3d3LmZkYS5nb3YvbWVkaWEvMDAwMDAwL2Rvd25sb2FkIl1d?page_from=1&page_to=2" \
    -H "x-api-key: YOUR_API_KEY"
  ```

  ```python Python theme={null}
  import requests

  document_id = "WyJmZGFfNDgzIixbImh0dHBzOi8vd3d3LmZkYS5nb3YvbWVkaWEvMDAwMDAwL2Rvd25sb2FkIl1d"
  response = requests.get(
      f"https://rhizomeai.com/api/v3/documents/{document_id}",
      headers={"x-api-key": "YOUR_API_KEY"},
      params={"page_from": 1, "page_to": 2},
  )
  response.raise_for_status()
  data = response.json()
  print(f"{data['title']}: {data['total_pages']} pages")
  ```

  ```javascript JavaScript theme={null}
  const documentId =
    "WyJmZGFfNDgzIixbImh0dHBzOi8vd3d3LmZkYS5nb3YvbWVkaWEvMDAwMDAwL2Rvd25sb2FkIl1d";
  const response = await fetch(
    `https://rhizomeai.com/api/v3/documents/${documentId}?page_from=1&page_to=2`,
    { headers: { "x-api-key": "YOUR_API_KEY" } }
  );

  const data = await response.json();
  console.log(`${data.title}: ${data.total_pages} pages`);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "document_id": "WyJmZGFfNDgzIixbImh0dHBzOi8vd3d3LmZkYS5nb3YvbWVkaWEvMDAwMDAwL2Rvd25sb2FkIl1d",
    "dataset": "fda_483",
    "title": "Example Pharma Inc.",
    "url": "https://www.fda.gov/media/000000/download",
    "total_pages": 14,
    "pages": [
      {
        "page_num": 1,
        "text": "DEPARTMENT OF HEALTH AND HUMAN SERVICES FOOD AND DRUG ADMINISTRATION..."
      },
      {
        "page_num": 2,
        "text": "OBSERVATION 1. There is a failure to thoroughly review the failure of a batch to meet its specifications. Sterility test..."
      }
    ],
    "next_page_from": 3
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.