# SDK quickstart (/docs/sdk-quickstart)

Get a document's page-by-page structured content into your application. In this guide, a short script uploads the statement and returns its recovered pages. You'll display the result in your terminal to inspect what your workflow will receive.

You'll need Node.js 24 and a Pagelet workspace. If you haven't created a workspace yet, follow the [portal setup](/docs/portal-quickstart#1-open-your-workspace).

## 1. Create an API key [#1-create-an-api-key]

In the portal, open **API Keys** and select **Create key**. Give the key a name. For this example, select: **Create uploads**, **Read job status**, and **Read results**.

Select **Create key** and copy the key. The portal shows the full key only once.

## 2. Set up the example [#2-set-up-the-example]

Create a folder and install the SDK:

```sh
mkdir statement-example
cd statement-example
npm init -y
npm install @pagelet-ai/sdk
```

Download the [sample statement](/docs/samples/statement.pdf) into this folder as `statement.pdf`. To use your own document, replace the file path in the example below.

Create a `.env` file in the same folder, replacing `your_api_key` with your key:

```dotenv
PAGELET_API_KEY=your_api_key
```

Keep `.env` out of version control. Use the SDK in your backend or local scripts; don't put this key in browser code.

## 3. Extract the content [#3-extract-the-content]

Save this as `extract.mjs`:

```js
import { Pagelet } from "@pagelet-ai/sdk"

const client = new Pagelet()
const result = await client.documents.create({ file: "statement.pdf" })

for (const page of result.pages) {
  console.log(page.page_number, page.markdown)
}
```

Run it:

```sh
node --env-file=.env extract.mjs
```

Node loads your `.env` file, and the client reads `PAGELET_API_KEY` automatically.

`documents.create` uploads the file and waits for its result. Your terminal then shows the extracted content from each page, in document order. You can inspect the returned content before passing it into the next step of your workflow.

## Understand the response [#understand-the-response]

`documents.create` returns the document and its recovered pages. This example shows a short Markdown excerpt from one page; IDs are examples.

```json
{
  "job": {
    "id": "job_00000000000000000000000001",
    "status": "completed"
  },
  "document": {
    "id": "doc_00000000000000000000000001",
    "filename": "statement.pdf",
    "media_type": "application/pdf",
    "page_count": 4,
    "content_status": "available",
    "confidence_score": 90
  },
  "pages": [
    {
      "page_number": 1,
      "markdown": "# ALDER COAST\n\n**Your checking statement**\n\nSeptember 1, 2026 - September 30, 2026\n\n## About this statement\n\nYour activity appears in posting order on the following pages. Debit and credit columns separate money leaving the account from money received. The running balance reflects each posted transaction.",
      "confidence_score": 90,
      "warnings": []
    }
  ],
  "warnings": []
}
```

- `document.id` identifies the document for later reads and searches.
- `pages` contains the recovered content in source order. Each page has a `page_number` and `markdown`.
- `job` identifies the processing request and its final status.
- `warnings` identifies content that needs attention. Individual pages can also have warnings.

The complete result includes all four pages. [Read results](/docs/results) explains page access, confidence estimates, and missing content.

## Use the result [#use-the-result]

Each item in `result.pages` contains a page's Markdown and its source page number. Keep them together so your application or AI agent can refer back to the original page.

Save `result.document.id` with your application's record. Use [`documents.result`](/docs/sdk-reference#documentsresult) to retrieve the result later, [`documents.page`](/docs/sdk-reference#documentspage) to read one page, or [Search](/docs/search#search-with-the-sdk) to find a passage. You don't need to upload the file again.

For background work, [`jobs.create`](/docs/background-processing) returns after submission. Your application can collect the result later or receive a webhook when processing finishes.

## Check for missing content [#check-for-missing-content]

Check `result.warnings` and each page's `warnings` before using the content. A page's `markdown` is `null` when extraction failed and an empty string when no text was found. Preserve that distinction so a missing page doesn't appear to be blank.
