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

# DocRaptor plugin

> Convert HTML into PDF and XML into Excel with DocRaptor - create a document and get the file back, queue asynchronous conversions and download them when done, host finished documents at paid public URLs and expire them again.

Use **DocRaptor** through Corsair: one client, typed API calls.

Sign up at [https://docraptor.com/signup](https://docraptor.com/signup) and read the API key from your account dashboard. The key is the HTTP Basic username with an empty password, and the plugin builds that header for you. DocRaptor's public test key `YOUR_API_KEY_HERE` makes test documents too. Things to know before you send:

* **Test mode is the default.** The plugin sends `test: true` unless you set `test: false`, so documents are not charged against the plan, but PDFs carry a watermark and Excel output is cut to 20 rows. Set `test: false` only when you mean to spend quota. Every create is marked destructive, so the permission check runs before it.
* **Synchronous or asynchronous.** `documents.create` waits for the conversion (up to 60 seconds) and returns the file itself: base64 under the inline limit, or a file id when the host keeps files. `documents.createAsync` queues a conversion and returns a `status_id`; `documents.status` reads it back with `queued`, `working`, `completed` or `failed`, and `documents.download` fetches the finished file by its `download_id`.
* **Download URLs allow few fetches.** A non-hosted `download_url` can be fetched only a few times (as few as once, depending on the account's data retention setting) and disappears when retention expires. Download and store the file yourself.
* **Hosted documents are a paid add-on.** `documents.createHosted` and `documents.createHostedAsync` put the finished document on a public unbranded URL that is billed per download. The account's retention setting does not apply to them: a hosted URL stays up until `hosted_download_limit` fetches are used, `hosted_expires_at` passes, or `documents.expire` removes it. Hosted test documents allow five downloads and expire after one day.
* **Expiring is permanent.** `documents.expire` removes a hosted document immediately and cannot be undone.
* **The throttle is a 403, not a 429.** More than 30 simultaneous generation requests are refused with a 403 whose message names simultaneous requests; the plugin retries that once on reads. Other 403s mean a missing permission or a denied listing and are never retried. Errors are core `ApiError`s whose `body` holds DocRaptor's XML or JSON error text; `describeDocRaptorErrorBody` reads it.
* **Listing needs a real key.** The public test key is refused `documents.list` with a 403, so its row fields are unverified and pass through as sent.
* **Webhooks.** DocRaptor's `callback_url` posts completion notices to your own endpoint. The callback is not signed, so the plugin does not receive it as a webhook; poll `documents.status` instead.

**What you get:**

* 9 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/docraptor better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/docraptor better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/docraptor better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/docraptor better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { docraptor } from '@corsair-dev/docraptor';

export const corsair = createCorsair({
	plugins: [
		docraptor(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the DocRaptor API key before the first call: `pnpm corsair setup --plugin=docraptor --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> docraptor()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'docraptor',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**Read where a document stands**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.docraptor.api.documents.status({ statusId: '123454321' });
```

**Expire a hosted document**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.docraptor.api.documents.expire({ downloadId: '123-456-abc' });
```

See the full list on the [API](https://docs.corsair.dev/plugins/docraptor/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/docraptor/api.md)
>
> Every `docraptor.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


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