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

# Overview

> AI document processing with Nanonets - extract fields from images and URLs with OCR models, train models, review and correct predicted files, approve or delete them, and query connected data stores.

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

Create an API key at app.nanonets.com/#keys (Extract Data screen, Account Info, API Keys, "Add a New Key"); the first key is issued automatically at signup. The key is sent as HTTP Basic auth with the key as username and an empty password. Things to know before you call:

* **Predictions are writes.** Every create call uploads a file to Nanonets and consumes API quota, so they are classified `write`, not `read`. Files are sent as `base64_data` (PNG or JPEG); the binary multipart `file` field is not wrapped.
* **`async: true`** switches a create call to the documented async variant: the response comes back pending with a `request_file_id`, which you poll with `predictions.getFileByFileId`. Nanonets documents no done flag on that route: the file is processed once its pages are listed with their `predicted_boxes`, under `unmoderated_images`, or under `moderated_images` after the file is approved. Recommended above 3 pages; results normally finish within \~5 minutes.
* **Quota and rate limits.** 402 means the free API call quota is exhausted and is never retried. 429 is per model per 1-minute window on the predict calls; the plugin waits the documented 30 seconds between retries (Retry-After is honored when sent), up to three times.
* **Paging is a day window.** `predictions.listFiles` takes `start_day_interval` and `current_batch_day` as days since 1970-01-01 GMT (floor of unix seconds over 86400) and returns moderated and unmoderated images for that window; walk the windows forward yourself.
* **`files.updateFields` replaces the whole field set of one page.** Read the page first (`predictions.getFileByPageId` or `predictions.listFiles`), then send its `id` with the full `moderated_boxes` array: unchanged boxes stay, new boxes need `is_new: true`, and any field you omit is deleted. Copy `day_since_epoch` and `hour_of_day` from the same read: they are required, because Nanonets looks the page up by them and answers 400 without them. `page` and `is_moderated` are optional. The request is sent as `text/plain` because that is the documented working sample.
* **Deleting is permanent.** `files.delete` removes the file and its predictions for good. `integrations.executeQuery` runs arbitrary SQL against a connected store (documented examples include UPDATE), so it is also classified destructive.
* **Training.** `models.uploadTrainingUrls` adds images by URL (pass `data` to label them: one entry per image with its `filename` URL and the boxes in `object`), then `models.train` retrains; the model state walks 2→3→4→5 (usable). `models.updateGuidelines` changes extraction behavior of Instant Learning models via natural-language instructions.
* **Webhooks.** Nanonets can POST document events to URLs you configure in its UI (Workflow → Exports → Webhooks), but it signs nothing, so the plugin receives none.

**What you get:**

* 17 typed API operations

## Setup

**1. Install**

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

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

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

```bash bun theme={null}
bun add corsair @corsair-dev/nanonets 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 { nanonets } from '@corsair-dev/nanonets';

export const corsair = createCorsair({
	plugins: [
		nanonets(),
	],
	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)
>
> No setup required yet. When you make your first request as a tenant, Corsair prompts for the API key.
>
> ```ts theme={null}
> nanonets()
> ```
>
> 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: 'nanonets',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**Fetch a prediction file by ID**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.nanonets.api.predictions.getFileByFileId({ model_id: 'd4d3beec-1029-497a-8d4c-8a3e2de6e7f2', request_file_id: '68d2b0f6-af9c-4c71-9d3e-2f3a4b5c6d7e' });
```

**Extract fields from an image URL**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.nanonets.api.predictions.createFromUrls({
	model_id: 'd4d3beec-1029-497a-8d4c-8a3e2de6e7f2',
	urls: ['https://example.com/invoice.png'],
});
```

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

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/nanonets/api.md)
>
> Every `nanonets.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.